DbSet content differs from database content

106 views Asked by At

I'm using Entity Framework with Code First in C#.

I'm trying to display the contents of one of the tables from my database using the DbSet but it differs from the actual content of that table in the database. I'm looking at the DbSet and the table at the same time but the DbSet hasn't been updated.

This is what I see: The table in the database

The DbSet while debugging

I would like to understand why the element number 4 of the set has a different type than the others.

If I close the program and re open it then the DbSet gets updated.

Thanks

1

There are 1 answers

0
bubi On

The element number 4 is an element you just created so the EF does not have created a proxy for it. The problem that the element does not reflect the database changes could be several. For example,
- the element 4 is just created in memory than someone else (another context) update the element. - the element 4 is just created in memory with some null fields and SQL addedd some default values.
- ...