我有一个LINQ查询在那里我试图返回所有MlaArticles
这涉及到所有其他WebObjects
但我得到的错误:The specified type member 'RelatedWebObjectIds' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
选择所有相关的对象
这里的型号......
public abstract class WebObject : IValidatableObject
{
public WebObject()
{
this.Id = Guid.NewGuid();
RelatedTags = new List<Tag>();
RelatedWebObjects = new List<WebObject>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public virtual ICollection<WebObject> RelatedWebObjects { get; set; }
public IList<Guid> RelatedWebObjectIds { get; set; }
}
感谢您的帮助......
List<MlaArticle> assignedWebObjects = (from e in db.MlaArticles
where
(from w in db.WebObjects
from r in w.RelatedWebObjectIds
where w.Id == id
select r).Contains(e.Id)
select e).OrderBy(x => x.Title).ToList();
新查询。产生不同的错误:WebObject does not contain a definition for 'Contains' and the best extension method overload ... has some invalid arguments.
List<MlaArticle> assignedWebObjects = (from e in db.MlaArticles
where
(from w in db.WebObjects
from r in w.RelatedWebObjects
where w.Id == id
select r.RelatedWebObjectIds).Contains(e.Id)
select e).OrderBy(x => x.Title).ToList();
是的,有。但是当我引用RelatedWebObjects时,我得到一个Contains的错误:'WebObject不包含'Contains'的定义和最好的扩展方法重载...有一些无效的参数。' – bflemi3
你确定你使用的是相同的查询吗?也许你忘了用'select r.Id'替换'select r'? –
它需要是r.RelatedWebObjectIds,但仍会抛出相同的错误。我会把我的新查询放在上面...... – bflemi3