Is there any particular reason why adding an item to an EF4.1 collection, saving it to the database and then selecting that collection out again would produce weird results?
When I do the initial load, all the items in the collection are of a type System.Data.Entity.DynamicProxies.MyClassName_LongString
, so the following select on the collection works:
var y = MyCollection.Where(x => x.ValidTo == null).First();
Yes, there is always an item in the collection which fulfills that criteria. Always.
However, if I select the collection, add a new item to it, save the changes and then on the same context select the collection again, the last item in the collection (the new one), is not a dynamic proxy, but instead is of my POCO type (Moo.Model.MyClassName
).
Carrying out the same select from above on that version of the collection throws a null reference exception - even though the last item (the non-dynamic proxy one) does indeed match the criteria, which I have confirmed through watching the collection manually...
Load the collection from another context after the changes and the behaviour doesn't show itself - they are all dynamic proxies, and the select works.
Does anyone have any idea as to whats causing this behaviour?