我有三个简单的课程
public class Asset
{
public int ID {get;set;}
public virtual Category {get;set;}
}
public class Category
{
public int ID {get;set;}
}
public class AssetCollection
{
public int ID {get;set;}
public virtual ICollection<Asset> Assets {get;set;}
??????public bool HasAssetWithCategory(int ID)
{
????????????
}
}
我希望能够像这样选择上下文HasAssetWithCategory
var assets = context.AssetCollections.Where(m => m.HasAssetWithCategory(SomeID));
即使从哪里开始,我也没有线索。
答案 0 :(得分:0)
HasAssetCategory是您已定义且无法转换为SQL语句的方法。因此,EntityFramework无法执行您拥有的查询。相反,您应该尝试此查询,
var assets = context.AssetCollections.Where(m => m.Assets.Any(a => a.ID == someID));