question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow model building outside of OnModelCreating

See original GitHub issue

With EFCore 2, in order to have all mappings explicit, I create the model with an empty ConventionSet.

This scenario causes an exception with EFCore 2.1 (both preview1 and preview2)

Don’t know if this is an actual bug or just something that I’m required to add as a convention in order to have a 100% by code mapping. Maybe there’s some documentation that I can’t find?

System.ArgumentNullException : Value cannot be null.
Parameter name: relationalTypeMapping
Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
Microsoft.EntityFrameworkCore.Storage.Internal.TypeMappedRelationalParameter..ctor(String invariantName, String name, RelationalTypeMapping relationalTypeMapping, Nullable`1 nullable)
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder.AddParameter(String invariantName, String name, IProperty property)
Microsoft.EntityFrameworkCore.Storage.RelationalCommandBuilderExtensions.AddParameter(IRelationalCommandBuilder commandBuilder, String invariantName, String name, IProperty property)
Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.CreateStoreCommand()
Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
TestProject.UnitTest1.Test1() in UnitTest1.cs

Steps to reproduce

Test code attached. Switch between EFCore 2 and 2.1 preview in order to see the different behavior.

TestProject.zip

Further technical details

EF Core version: 2.1 preview 2 Database Provider: Sqlite Operating system: window 10 1803 17134.1 (and previous) IDE: at the moment 15.7 preview 4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:39 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
merrycodercommented, Sep 12, 2018

Same for me as for @sadjadbp - blocks me from upgrading to 2.1.

1reaction
ajcvickerscommented, Sep 20, 2018

Triage: we will look into adding a Finalize/Build or similar method to the model that will make it possible to build the model externally from the context but still have all the conventions execute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow model building outside of OnModelCreating #11738
I have a full complex model over which I have full control on how the mapping is defined and how my domain classes...
Read more >
Creating and Configuring a Model - EF Core
This is the most powerful method of configuration and allows configuration to be specified without modifying your entity classes.
Read more >
Net Core Lazyloading issue when model built outside the ...
The problem is that lazy loading proxies package uses convention which is executed after the model is built and modifies it.
Read more >
A Cleaner Way To Do Entity Configuration With EF Core
You should always aim to have specific ViewModels returned from your API and not return out your entity models. Ever. I get that...
Read more >
Overriding the Context's OnModelCreating Method (How To)
Let's override the Context class' `OnModelCreating` method so that we can customize EF's conventions and use EF's fluent API to refine our ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found