diff --git a/All.sln b/All.sln index a149f3cc8a7..8bd06458baa 100644 --- a/All.sln +++ b/All.sln @@ -334,14 +334,14 @@ Global {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Release|Any CPU.ActiveCfg = Release|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Debug|Any CPU.Build.0 = Debug|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Release|Any CPU.ActiveCfg = Release|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Release|Any CPU.Build.0 = Release|Any CPU {2487950B-403A-482C-8ED3-CCF31E9E677F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2487950B-403A-482C-8ED3-CCF31E9E677F}.Debug|Any CPU.Build.0 = Debug|Any CPU {2487950B-403A-482C-8ED3-CCF31E9E677F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2487950B-403A-482C-8ED3-CCF31E9E677F}.Release|Any CPU.Build.0 = Release|Any CPU {8F722A02-71A4-4787-ACD8-FB7D5B7AE648}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8F722A02-71A4-4787-ACD8-FB7D5B7AE648}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F722A02-71A4-4787-ACD8-FB7D5B7AE648}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -358,10 +358,6 @@ Global {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Release|Any CPU.Build.0 = Release|Any CPU - {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -415,13 +411,13 @@ Global {F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749} {CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749} {F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749} + {59C1CEDE-AA45-41FE-8098-6279A72C421A} = {258D5057-81B9-40EC-A872-D21E27452749} {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {2487950B-403A-482C-8ED3-CCF31E9E677F} = {258D5057-81B9-40EC-A872-D21E27452749} {8F722A02-71A4-4787-ACD8-FB7D5B7AE648} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {01F86E65-6448-424C-AAB5-9C6427EF6FD4} = {258D5057-81B9-40EC-A872-D21E27452749} {3D935B7D-80BD-49AD-BDC9-E1B0C9D9494F} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3} = {258D5057-81B9-40EC-A872-D21E27452749} - {59C1CEDE-AA45-41FE-8098-6279A72C421A} = {258D5057-81B9-40EC-A872-D21E27452749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705} diff --git a/eng/testing/linker/SupportFiles/.editorconfig b/eng/testing/linker/SupportFiles/.editorconfig index 276d67e2788..bd00e69c49b 100644 --- a/eng/testing/linker/SupportFiles/.editorconfig +++ b/eng/testing/linker/SupportFiles/.editorconfig @@ -9,4 +9,3 @@ dotnet_analyzer_diagnostic.category-AOT.severity = error dotnet_analyzer_diagnostic.category-Trimming.severity = error dotnet_diagnostic.SA0001.severity = none dotnet_diagnostic.SA1516.severity = none - diff --git a/eng/testing/linker/trimmingTests.targets b/eng/testing/linker/trimmingTests.targets index 465b42f4695..2174c5ab2a9 100644 --- a/eng/testing/linker/trimmingTests.targets +++ b/eng/testing/linker/trimmingTests.targets @@ -70,7 +70,7 @@ <_additionalProjectReferencesString>@(_additionalProjectReference, '%0a ') - + contentfiles;analyzers;build @@ -150,7 +150,7 @@ Outputs="_unused"> - + diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs index e4556778ab1..20402f1e7fa 100644 --- a/src/EFCore/Internal/DbContextServices.cs +++ b/src/EFCore/Internal/DbContextServices.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; namespace Microsoft.EntityFrameworkCore.Internal; @@ -85,7 +86,9 @@ private IModel CreateModel(bool designTime) return modelFromOptions == null || (designTime && modelFromOptions is not Metadata.Internal.Model) - ? dependencies.ModelSource.GetModel(_currentContext!.Context, dependencies, designTime) + ? RuntimeFeature.IsDynamicCodeSupported + ? dependencies.ModelSource.GetModel(_currentContext!.Context, dependencies, designTime) + : throw new InvalidOperationException(CoreStrings.NativeAotNoCompiledModel) : dependencies.ModelRuntimeInitializer.Initialize(modelFromOptions, designTime, dependencies.ValidationLogger); } finally diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 0fa7510a1eb..662e5874937 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -1745,6 +1745,12 @@ public static string NamedIndexWrongType(object? indexName, object? entityType) GetString("NamedIndexWrongType", nameof(indexName), nameof(entityType)), indexName, entityType); + /// + /// Model building is not supported when publishing with NativeAOT. Use a compiled model. + /// + public static string NativeAotNoCompiledModel + => GetString("NativeAotNoCompiledModel"); + /// /// The type of navigation '{1_entityType}.{0_navigation}' is '{foundType}' which is an array type. Collection navigations cannot be arrays. /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 9fd655d1119..f300271c954 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1083,6 +1083,9 @@ The index with name {indexName} cannot be removed from the entity type '{entityType}' because no such index exists on that entity type. + + Model building is not supported when publishing with NativeAOT. Use a compiled model. + The type of navigation '{1_entityType}.{0_navigation}' is '{foundType}' which is an array type. Collection navigations cannot be arrays. diff --git a/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj b/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj index be8ce9698b9..cec5f434fc2 100644 --- a/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj +++ b/src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj @@ -15,12 +15,13 @@ Microsoft.Data.Sqlite.SqliteException Microsoft.Data.Sqlite.SqliteFactory Microsoft.Data.Sqlite.SqliteParameter Microsoft.Data.Sqlite.SqliteTransaction - netstandard2.0;net6.0 + $(DefaultNetCoreTargetFramework);netstandard2.0;net6.0 3.6 true Microsoft.Data.Sqlite.Core.ruleset SQLite;Data;ADO.NET https://docs.microsoft.com/dotnet/standard/data/sqlite/ + true diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs b/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs index ca5a6d2b8bd..50031bc36f0 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs @@ -315,7 +315,7 @@ public override string GetDataTypeName(int ordinal) /// /// The zero-based column ordinal. /// The data type of the column. -#if NET6_0_OR_GREATER +#if NET8_0_OR_GREATER [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)] #endif public override Type GetFieldType(int ordinal) @@ -623,75 +623,74 @@ public override DataTable GetSchemaTable() var schemaTable = new DataTable("SchemaTable"); - var ColumnName = new DataColumn(SchemaTableColumn.ColumnName, typeof(string)); - var ColumnOrdinal = new DataColumn(SchemaTableColumn.ColumnOrdinal, typeof(int)); - var ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int)); - var NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short)); - var NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short)); - - var DataType = new DataColumn(SchemaTableColumn.DataType, typeof(Type)); - var DataTypeName = new DataColumn("DataTypeName", typeof(string)); + var columnNameColumn = new DataColumn(SchemaTableColumn.ColumnName, typeof(string)); + var columnOrdinalColumn = new DataColumn(SchemaTableColumn.ColumnOrdinal, typeof(int)); + var columnSizeColumn = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int)); + var numericPrecisionColumn = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short)); + var numericScaleColumn = new DataColumn(SchemaTableColumn.NumericScale, typeof(short)); + var dataTypeColumn = CreateDataTypeColumn(); + var dataTypeNameColumn = new DataColumn("DataTypeName", typeof(string)); - var IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(bool)); - var AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool)); + var isLongColumn = new DataColumn(SchemaTableColumn.IsLong, typeof(bool)); + var allowDBNullColumn = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool)); - var IsUnique = new DataColumn(SchemaTableColumn.IsUnique, typeof(bool)); - var IsKey = new DataColumn(SchemaTableColumn.IsKey, typeof(bool)); - var IsAutoIncrement = new DataColumn(SchemaTableOptionalColumn.IsAutoIncrement, typeof(bool)); + var isUniqueColumn = new DataColumn(SchemaTableColumn.IsUnique, typeof(bool)); + var isKeyColumn = new DataColumn(SchemaTableColumn.IsKey, typeof(bool)); + var isAutoIncrementColumn = new DataColumn(SchemaTableOptionalColumn.IsAutoIncrement, typeof(bool)); - var BaseCatalogName = new DataColumn(SchemaTableOptionalColumn.BaseCatalogName, typeof(string)); - var BaseSchemaName = new DataColumn(SchemaTableColumn.BaseSchemaName, typeof(string)); - var BaseTableName = new DataColumn(SchemaTableColumn.BaseTableName, typeof(string)); - var BaseColumnName = new DataColumn(SchemaTableColumn.BaseColumnName, typeof(string)); + var baseCatalogNameColumn = new DataColumn(SchemaTableOptionalColumn.BaseCatalogName, typeof(string)); + var baseSchemaNameColumn = new DataColumn(SchemaTableColumn.BaseSchemaName, typeof(string)); + var baseTableNameColumn = new DataColumn(SchemaTableColumn.BaseTableName, typeof(string)); + var baseColumnNameColumn = new DataColumn(SchemaTableColumn.BaseColumnName, typeof(string)); - var BaseServerName = new DataColumn(SchemaTableOptionalColumn.BaseServerName, typeof(string)); - var IsAliased = new DataColumn(SchemaTableColumn.IsAliased, typeof(bool)); - var IsExpression = new DataColumn(SchemaTableColumn.IsExpression, typeof(bool)); + var baseServerNameColumn = new DataColumn(SchemaTableOptionalColumn.BaseServerName, typeof(string)); + var isAliasedColumn = new DataColumn(SchemaTableColumn.IsAliased, typeof(bool)); + var isExpressionColumn = new DataColumn(SchemaTableColumn.IsExpression, typeof(bool)); var columns = schemaTable.Columns; - columns.Add(ColumnName); - columns.Add(ColumnOrdinal); - columns.Add(ColumnSize); - columns.Add(NumericPrecision); - columns.Add(NumericScale); - columns.Add(IsUnique); - columns.Add(IsKey); - columns.Add(BaseServerName); - columns.Add(BaseCatalogName); - columns.Add(BaseColumnName); - columns.Add(BaseSchemaName); - columns.Add(BaseTableName); - columns.Add(DataType); - columns.Add(DataTypeName); - columns.Add(AllowDBNull); - columns.Add(IsAliased); - columns.Add(IsExpression); - columns.Add(IsAutoIncrement); - columns.Add(IsLong); + columns.Add(columnNameColumn); + columns.Add(columnOrdinalColumn); + columns.Add(columnSizeColumn); + columns.Add(numericPrecisionColumn); + columns.Add(numericScaleColumn); + columns.Add(isUniqueColumn); + columns.Add(isKeyColumn); + columns.Add(baseServerNameColumn); + columns.Add(baseCatalogNameColumn); + columns.Add(baseColumnNameColumn); + columns.Add(baseSchemaNameColumn); + columns.Add(baseTableNameColumn); + columns.Add(dataTypeColumn); + columns.Add(dataTypeNameColumn); + columns.Add(allowDBNullColumn); + columns.Add(isAliasedColumn); + columns.Add(isExpressionColumn); + columns.Add(isAutoIncrementColumn); + columns.Add(isLongColumn); for (var i = 0; i < FieldCount; i++) { var schemaRow = schemaTable.NewRow(); - schemaRow[ColumnName] = GetName(i); - schemaRow[ColumnOrdinal] = i; - schemaRow[ColumnSize] = -1; - schemaRow[NumericPrecision] = DBNull.Value; - schemaRow[NumericScale] = DBNull.Value; - schemaRow[BaseServerName] = _command.Connection!.DataSource; + schemaRow[columnNameColumn] = GetName(i); + schemaRow[columnOrdinalColumn] = i; + schemaRow[columnSizeColumn] = -1; + schemaRow[numericPrecisionColumn] = DBNull.Value; + schemaRow[numericScaleColumn] = DBNull.Value; + schemaRow[baseServerNameColumn] = _command.Connection!.DataSource; var databaseName = sqlite3_column_database_name(_record.Handle, i).utf8_to_string(); - schemaRow[BaseCatalogName] = databaseName; + schemaRow[baseCatalogNameColumn] = databaseName; var columnName = sqlite3_column_origin_name(_record.Handle, i).utf8_to_string(); - schemaRow[BaseColumnName] = columnName; - schemaRow[BaseSchemaName] = DBNull.Value; + schemaRow[baseColumnNameColumn] = columnName; + schemaRow[baseSchemaNameColumn] = DBNull.Value; var tableName = sqlite3_column_table_name(_record.Handle, i).utf8_to_string(); - schemaRow[BaseTableName] = tableName; - schemaRow[DataType] = GetFieldType(i); + schemaRow[baseTableNameColumn] = tableName; + schemaRow[dataTypeColumn] = GetFieldType(i); var dataTypeName = GetDataTypeName(i); - schemaRow[DataTypeName] = dataTypeName; - schemaRow[IsAliased] = columnName != GetName(i); - schemaRow[IsExpression] = columnName == null; - schemaRow[IsLong] = DBNull.Value; + schemaRow[dataTypeNameColumn] = dataTypeName; + schemaRow[isAliasedColumn] = columnName != GetName(i); + schemaRow[isExpressionColumn] = columnName == null; + schemaRow[isLongColumn] = DBNull.Value; var eponymousVirtualTable = false; if (tableName != null @@ -708,7 +707,7 @@ public override DataTable GetSchemaTable() command.Parameters.AddWithValue("$column", columnName); var cnt = (long)command.ExecuteScalar()!; - schemaRow[IsUnique] = cnt != 0; + schemaRow[isUniqueColumn] = cnt != 0; command.Parameters.Clear(); var columnType = "typeof(\"" + columnName.Replace("\"", "\"\"") + "\")"; @@ -721,7 +720,7 @@ public override DataTable GetSchemaTable() .AppendLine("LIMIT 1;").ToString(); var type = (string?)command.ExecuteScalar(); - schemaRow[DataType] = + schemaRow[dataTypeColumn] = (type != null) ? SqliteDataRecord.GetFieldType(type) : SqliteDataRecord.GetFieldTypeFromSqliteType( @@ -741,9 +740,9 @@ public override DataTable GetSchemaTable() out var notNull, out var primaryKey, out var autoInc); SqliteException.ThrowExceptionForRC(rc, _command.Connection.Handle); - schemaRow[IsKey] = primaryKey != 0; - schemaRow[AllowDBNull] = notNull == 0; - schemaRow[IsAutoIncrement] = autoInc != 0; + schemaRow[isKeyColumn] = primaryKey != 0; + schemaRow[allowDBNullColumn] = notNull == 0; + schemaRow[isAutoIncrementColumn] = autoInc != 0; } } @@ -751,6 +750,19 @@ public override DataTable GetSchemaTable() } return schemaTable; + +#if NET6_0_OR_GREATER + [UnconditionalSuppressMessage("Trimming", "IL2111:Method with parameters or return value with `DynamicallyAccessedMembersAttribute`" + + " is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.", + Justification = "This is about System.Type.TypeInitializer.get. It is accessed via reflection" + + " as the type parameter in DataColumn is annotated with DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties" + + " However, reflection is only used for nullable columns.")] +#endif + static DataColumn CreateDataTypeColumn() + => new(SchemaTableColumn.DataType, typeof(Type)) + { + AllowDBNull = false + }; } } } diff --git a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs index bfd0b56726a..dc2a436f1c0 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs @@ -1,4 +1,4 @@ -// +// using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.NativeAotTests.Models; diff --git a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs index 0c65db5fe25..3375782ab20 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs @@ -1,4 +1,4 @@ -// +// using Microsoft.EntityFrameworkCore.Metadata; #pragma warning disable 219, 612, 618 diff --git a/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs b/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs index 259502cd902..af40f39c4d5 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs @@ -1,4 +1,4 @@ -// +// using System.Reflection; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; diff --git a/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj b/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj index dcfb9993c17..c8bacbc3be4 100644 --- a/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj +++ b/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj @@ -4,6 +4,7 @@ Exe $(DefaultNetCoreTargetFramework) enable + true true Microsoft.EntityFrameworkCore.NativeAotTests Microsoft.EntityFrameworkCore.NativeAotTests @@ -12,6 +13,13 @@ + + + + + + + diff --git a/test/EFCore.NativeAotTests/EndToEnd.cs b/test/EFCore.NativeAotTests/EndToEnd.cs index c4b38d8a53f..7511645cb9a 100644 --- a/test/EFCore.NativeAotTests/EndToEnd.cs +++ b/test/EFCore.NativeAotTests/EndToEnd.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.NativeAotTests.Models; diff --git a/test/EFCore.NativeAotTests/Models/NativeAotContext.cs b/test/EFCore.NativeAotTests/Models/NativeAotContext.cs index a663d69567c..21d8f2fbf7d 100644 --- a/test/EFCore.NativeAotTests/Models/NativeAotContext.cs +++ b/test/EFCore.NativeAotTests/Models/NativeAotContext.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.NativeAotTests.CompiledModels; diff --git a/test/EFCore.NativeAotTests/Models/User.cs b/test/EFCore.NativeAotTests/Models/User.cs index d0876f73233..1904d61f160 100644 --- a/test/EFCore.NativeAotTests/Models/User.cs +++ b/test/EFCore.NativeAotTests/Models/User.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.EntityFrameworkCore.NativeAotTests.Models; diff --git a/test/EFCore.NativeAotTests/Sqlite.cs b/test/EFCore.NativeAotTests/Sqlite.cs new file mode 100644 index 00000000000..c5ced55c362 --- /dev/null +++ b/test/EFCore.NativeAotTests/Sqlite.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Data.Sqlite; + +SQLitePCL.Batteries_V2.Init(); + +using var connection = new SqliteConnection("Data Source=:memory:"); + +connection.Open(); + +var command = connection.CreateCommand(); +command.CommandText = "SELECT 1; SELECT 2;"; + +using var reader = command.ExecuteReader(); +var schema = reader.GetSchemaTable(); + +if (schema.Rows.Count != 1) +{ + return -1; +} + +if ((Type)schema.Rows[0]["DataType"] != typeof(long)) +{ + return -2; +} + +if ((string)schema.Rows[0]["DataTypeName"] != "INTEGER") +{ + return -3; +} + +var hasData = reader.Read(); + +if (reader.GetInt64(0) != 1L) +{ + return -4; +} + +var hasResults = reader.NextResult(); +hasData = reader.Read(); +if (reader.GetInt64(0) != 2L) +{ + return -5; +} + +if (reader.NextResult()) +{ + return -6; +} + +return 100; diff --git a/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj b/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj index 9cfac35f1e4..7ab7e728be7 100644 --- a/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj +++ b/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj @@ -4,12 +4,14 @@ Exe $(DefaultNetCoreTargetFramework) enable - Microsoft.EntityFrameworkCore.TrimmingTests + true + false Microsoft.EntityFrameworkCore.TrimmingTests + Microsoft.EntityFrameworkCore.TrimmingTests - + diff --git a/test/EFCore.TrimmingTests/Sqlite.cs b/test/EFCore.TrimmingTests/Sqlite.cs index e4173fc310e..c5ced55c362 100644 --- a/test/EFCore.TrimmingTests/Sqlite.cs +++ b/test/EFCore.TrimmingTests/Sqlite.cs @@ -13,23 +13,40 @@ command.CommandText = "SELECT 1; SELECT 2;"; using var reader = command.ExecuteReader(); +var schema = reader.GetSchemaTable(); + +if (schema.Rows.Count != 1) +{ + return -1; +} + +if ((Type)schema.Rows[0]["DataType"] != typeof(long)) +{ + return -2; +} + +if ((string)schema.Rows[0]["DataTypeName"] != "INTEGER") +{ + return -3; +} + var hasData = reader.Read(); if (reader.GetInt64(0) != 1L) { - return -1; + return -4; } var hasResults = reader.NextResult(); hasData = reader.Read(); if (reader.GetInt64(0) != 2L) { - return -1; + return -5; } if (reader.NextResult()) { - return -1; + return -6; } return 100;