我有一個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