0

I have three simple classes

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)
    {
    ????????????
    }
}

I want to be able select from context HasAssetWithCategory like this

var assets = context.AssetCollections.Where(m => m.HasAssetWithCategory(SomeID));

I do not have clue even where to start.

4

1 回答 1

0

HasAssetCategory 是您已定义的方法,无法转换为 SQL 语句。因此,EntityFramework 无法执行您拥有的查询。相反,你应该试试这个查询,

var assets = context.AssetCollections.Where(m => m.Assets.Any(a => a.ID == someID));
于 2013-04-25T15:21:20.163 回答