初始化列表使用具有外键的 EntityCollection
我正在尝试使用实体框架的结果初始化列表。这是错误:
LINQ to Entities 无法识别方法 'System.Collections.Generic.List1[Domain.Entities.Person] ToList[Person](System.Collections.Generic.IEnumerable
1[ Domain.Entities.Person])' 方法,并且该方法无法转换为存储表达式。
public List<Domain.Entities.Event> Events
{
get
{
Entities context = new Entities(connectionString);
return (from c in context.Events.Include("EventPeople")
select new Domain.Entities.Event()
{
ID = c.ID,
Title = c.Title,
Description = c.Description,
Date = c.Date,
People = (from ep in c.EventPeople
select new Domain.Entities.Person()
{
ID = ep.ID,
Name = ep.Name
}).ToList<Person>()
}).ToList<Domain.Entities.Event>();
}
}
I'm trying to initialize a List using results from the entity framework. Here is the error:
LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[Domain.Entities.Person] ToList[Person](System.Collections.Generic.IEnumerable
1[Domain.Entities.Person])' method, and this method cannot be translated into a store expression.
public List<Domain.Entities.Event> Events
{
get
{
Entities context = new Entities(connectionString);
return (from c in context.Events.Include("EventPeople")
select new Domain.Entities.Event()
{
ID = c.ID,
Title = c.Title,
Description = c.Description,
Date = c.Date,
People = (from ep in c.EventPeople
select new Domain.Entities.Person()
{
ID = ep.ID,
Name = ep.Name
}).ToList<Person>()
}).ToList<Domain.Entities.Event>();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要首先执行并返回 IEnumerable,然后使用 linq to Objects 创建一个列表
You need to execute first and return an IEnumerable then with linq to Objects create a list