I have a Tag and an Article object with a many-to-many relationship using Entity Framework 4.1.
I just want to retrieve a list of Articles which have a Tag. However the below code fails:
var db = new ArticleContext();
var tag = db.Tags.Find(tagId);
var articles= from article in db.Articles
where article.Tags.Contains(tag)
select article;
The error is “Only primitive types (‘such as Int32, String, and Guid’) are supported in this context.”
I understand that this is a known issue with EF ( http://msdn.microsoft.com/en-us/library/bb896317.aspx#RefNonScalarClosures ) but what is the best workaround?
Try this