gpt4 book ai didi

linq - 选择所有相关对象

转载 作者:行者123 更新时间:2023-12-02 05:08:47 25 4
gpt4 key购买 nike

我有一个 linq 查询,我试图返回与所有其他 WebObjects 相关的所有 MlaArticles 但我收到错误:The LINQ to Entities 不支持指定的类型成员“RelatedWebObjectIds”。仅支持初始化程序、实体成员和实体导航属性。

这是模型...

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 不包含“包含”的定义和最佳扩展方法重载...有一些无效参数。

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();

最佳答案

您的 MlaArticle 实体中是否有 RelatedWebObjects 导航属性?如果有,您可以改为这样做:

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.Id).Contains(e.Id)
select e).OrderBy(x => x.Title).ToList();

关于linq - 选择所有相关对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com