dotnet / dotnet/efcore

AOT : when precompiled model is not nativeaot compatible, we should throw an informative exception telling users to use -nativeaot switch

Open
#35,006 0 comments 2 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-precompiled-queries
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

repro steps:

create new EF app with

```
true
```

run compiled model command:

```
dotnet ef dbcontext optimize --output-dir Generated --precompile-queries
```

publish + run or just run in VS

Currently the exception we throw is:

```
Unhandled exception. System.InvalidOperationException: Model building is not supported when publishing with NativeAOT. Use a compiled model.
at Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty.<>c.b__44_0(IProperty property)
at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty.get_TypeMapping()
at Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty.Microsoft.EntityFrameworkCore.Metadata.IReadOnlyProperty.FindTypeMapping()
at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.FindRelationalTypeMapping(IReadOnlyProperty property)
at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnType(IReadOnlyProperty property)
at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnType(IProperty property)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateDefaultColumnMapping(ITypeBase typeBase, ITypeBase mappedType, TableBase defaultTable, TableMappingBase`1 tableMapping, Boolean isTph, Boolean isTpc)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddDefaultMappings(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.<>c__DisplayClass4_0.b__0()
at Microsoft.EntityFrameworkCore.RelationalModelExtensions.<>c.b__4_0(Func`1 f)
at Microsoft.EntityFrameworkCore.Infrastructure.RuntimeAnnotatableBase.<>c__22`2.b__22_0(String n, ValueTuple`3 t)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.RuntimeAnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func`2 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetRelationalModel(IModel model)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.