Сбой ядра EF при включении [закрыто] ⇐ C#
-
Гость
Сбой ядра EF при включении [закрыто]
I'm running into something I've never seen before with EF Core (latest version) under C# (latest version).
I have a DbContext that I add a number of entities to, with each entity participating in a many-to-many relationship.
After making those updates I can retrieve the many-to-many instances (NameConstituent in my schema) with no problem:
var transferDb = new TransferDb( transferDbName ); ...stuff added with no problems transferDb.SaveChanges(); var test = transferDb.NameConstituents.Include( nc => nc.Name ).ToList(); And yet, if I immediately create a new instance of the DbContext and execute the same retrieval code, an exception is thrown:
var db2 = new TransferDb( transferDbName ); // this next line throws the exception var test2 = db2.NameConstituents.Include(nc => nc.Name).ToList(); The exception message is:
Data is Null. This method or property cannot be called on Null values.
Unfortunately, that message means nothing to me.
I did take a look in the watch panel at DbSet. On the first DbContext each entry shows both the foreign key values (integers) and references to the foreign entity that link points at.
But that's not what I see when using the second DbContext. There, I only see the foreign key integer values -- there are not references to classes (the properties show as null...which is probably what the error message is trying to say).
I don't understand, though, while the related entities, visible in the first DbContext, aren't visible in the second.
Источник: https://stackoverflow.com/questions/780 ... on-include
I'm running into something I've never seen before with EF Core (latest version) under C# (latest version).
I have a DbContext that I add a number of entities to, with each entity participating in a many-to-many relationship.
After making those updates I can retrieve the many-to-many instances (NameConstituent in my schema) with no problem:
var transferDb = new TransferDb( transferDbName ); ...stuff added with no problems transferDb.SaveChanges(); var test = transferDb.NameConstituents.Include( nc => nc.Name ).ToList(); And yet, if I immediately create a new instance of the DbContext and execute the same retrieval code, an exception is thrown:
var db2 = new TransferDb( transferDbName ); // this next line throws the exception var test2 = db2.NameConstituents.Include(nc => nc.Name).ToList(); The exception message is:
Data is Null. This method or property cannot be called on Null values.
Unfortunately, that message means nothing to me.
I did take a look in the watch panel at DbSet. On the first DbContext each entry shows both the foreign key values (integers) and references to the foreign entity that link points at.
But that's not what I see when using the second DbContext. There, I only see the foreign key integer values -- there are not references to classes (the properties show as null...which is probably what the error message is trying to say).
I don't understand, though, while the related entities, visible in the first DbContext, aren't visible in the second.
Источник: https://stackoverflow.com/questions/780 ... on-include
Мобильная версия