I have a strange Problem with LINQ-To-SQL:
I have 3 tables - Feeds, FeedTags and Tags - where FeedTags is a m:n table for Feeds and Tags.
What I'm doing is inserting a new record into Feeds and then inserting a new record into FeedTags for this new Feed.
My problem is that, even if I query the Feed object fresh from the DB, the Feed.FeedTags property, which is the EntityRef to FeedTags, is empty (0 records):
// A bit simplified, adding Feed and Tag happens in different functions, but you get the idea context.Feeds.InsertOnSubmit(newFeed); context.SubmitChanges(); context.FeedTags.InsertOnSubmit(newTag); context.SubmitChanges(); var tags = context.Feeds.Single(f => f.Id == newFeed.Id).FeedTags;
tags has 0 records here. If I only query for the Feed object, it will be returned correctly, but also with 0 FeedTags records.
But when I explicitely query the FeedTags table for FeedTags with the new FeedId, I'll get the created tag back:
// Works as expected: var feedTag = context.FeedTags.Single(ft => ft.FeedId = newFeed.Id && ft.TagId == newTag.Id);
So, obviously everything got inserted correctly, but for some reason the parent object does include the created FeedTags. What could be wrong here?
When I restart the App, everything's working fine again, and a new query to the Feeds table will also include all created FeedTags.
I have no idea where to start to look - maybe someone has experienced this before and could point me in the right direction ...
preguntado el 05 de mayo de 13 a las 19:05