Comparison of user class objects is not supported in Linq to entities

The linq expression is:
var query = from p in _db.LogProjects
      where p.Well == well
      select p;
( Well is a user class )

An exception will be thrown:
Unable to create a constant value of type 'Closure type'. Only primitive types (for instance Int32, String and Guid) are supported in this context.

So, you can change the linq expression to:
var query = from p in _db.LogProjects
      where p.Well.WellID == well.WellID
      select p;

reference:
 ADO.NET Entity Framework Comparison Frustration
Entity Framework Comparison Frustration: Explained

posted on 2008-05-10 09:12  阳春三月  阅读(277)  评论(0编辑  收藏  举报

导航