Table has one Local entry, but Result is empty

Feb 3, 2014 at 10:28 AM
I Have the following Situation:
I Inserted one entry into the Table tblCenter
            var center = new tblCenter
                ID = 1,
                // ommited
Now I want to retrieve Data from this table:
            var centers = context.tblCenters.ToList(); // returns an empty list
            var center = context.tblCenters.SingleOrDefault(c => c.ID == 1); // returns null
            var centers2 = context.tblCenters.Local.ToList(); // returns a list with the added entry
            var center2 = context.tblCenters.Local.SingleOrDefault(c => c.ID == 1); // returns the added entry
Of course my code, that I want to test, calls context.tblCenters.SingleOrDefault(c => c.ID == 1); and the my test fails.

What do i have to do, to get the data from "Local" to "Normal" ?

Thanks in advance.
Feb 18, 2014 at 6:25 AM
Does nobody know how to fix this?
Any help would be greatly appreciated!
Feb 20, 2014 at 7:40 AM

Thank you for reporting this issue!

This seem to be a rather trivial scenario that just should work. However, I do not see anything wrong in your code.

May I ask you to provide a complete little proof of concept solution?
Feb 22, 2014 at 6:21 PM
I'm sorry!
When i put together a simple Solution to demonstrate the error, i found out that my code had context.SaveChanges() in a try clause and it was throwing an error.
I had a bad foreign keys and duplicate id's. (My real initialization code is a couple hundret lines)

However it would be nice if the foreign key error message would not be hidden inside a couple InnerExceptions, so you can see them upfront.
Also i found out that duplicate key exception are displayed as "Generic Exception". A more specific error message would be nice :)
Marked as answer by wertzui on 2/28/2014 at 4:56 AM
Feb 24, 2014 at 2:32 PM
It would be nice if the DB threw a nice, consistent, and understandable set of exceptions when the usual assortment of database conditions arose - foreign key, uniqueness constraint, missing record, etc.

Unfortunately, EF doesn't do that, and SQL server doesn't do that.

What would make Effort most useful would be to generate the same exceptions that SQL Server does, in the same situations.