Сбой ядра EF при включении [закрыто]C#

Место общения программистов C#
Ответить
Anonymous
 Сбой ядра EF при включении [закрыто]

Сообщение Anonymous »


Update

I have determined (a) what the problem was, (b) how to fix it, and (c) how to simplify the diagnostic process whenever something similar pops up again.

However, none of that information will ever be made available by me on StackOverflow unless and until someone with the authority to effect change within the StackOverflow community (a) apologizes to me for both the unhelpful feedback posted in some of the comments and (b) commits to improving the environment within StackOverflow.

Because that environment is extremely dysfunctional. And that's not just my opinion -- check out recent commentary on reddit.

Original Post

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»