当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How to use TypeOf with Include statment Linq

问题描述:

Following are my entity objects

public class Asset {...}

public class Picture : Asset {...}

public class Video : Asset {...}

public class Audio : Asset {...}

public class Project

{

...

public ICollection<Asset> Assets{get;set;}

...

}

How can request db.Projects.Include(x=>x.Assets.OfType<Picutre>()); using Linq, ie. to Query only Picture from List of Assets under Project.

Any Suggestions would help.. Thanks in Advance.

网友答案:

Can you try this?

var projects = from p in db.Projects
select new 
{
  Project = p,
  Pictures = p.Assets.Where(a => a is Picture)
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: