【发布时间】:2014-09-25 13:21:22
【问题描述】:
我必须在 where 子句中有两个 ICollections 进行查询,但我尝试过的没有任何工作在这里是我尝试过的:
var segmentActivity = db.Activities.Where(x => x.Segment.Link == link).ToList();
ICollection<Heading> hd = new List<Heading>();
foreach(var activity in segmentActivity)
{
hd.Add(db.Headings.Where(x => x.ActivityId == activity.Id).First());
}
ICollection<ProdutoSegmentoVM> produtos = new List<ProdutoSegmentoVM>();
foreach(var produto in hd)
{
//this is the where clause that i'm having problem v
produtos.Add(db.Products.Where(x => hd.Contains(x.Headings.Where(h => h.Id == produto.Id).First())).Select(x => new ProdutoSegmentoVM()
{
Id = x.Id,
Description = x.Description,
IsSpecification = (x.Specifications != null) ? true : false,
Specification = (x.Specifications != null) ? x.Specifications.Select(s => new SpecItemVM()
{
Attribute = s.Attribute,
Detail = s.SpecificationValues.Select(v => v.Detail).ToList()
})
.ToList() : null,
Image = x.PrimaryImage.Name,
SubTitle = x.Subtitle,
Title = x.TitleMetadata
})
.First());
抛出的异常是:“此上下文仅支持原始类型或枚举类型。”
编辑:标题是一个ICollection
【问题讨论】:
标签: c# sql linq entity-framework