LINQ to Entities 中不可用的实体属性
这是我的简化示例问题。
我有两个从 SQL Server 数据库建模的实体:
- 订单(可用列 = OrderID、PackageCount、ManufactureDate、ShipDate、StatusID) 主键 = OrderID)
- OrderRecipients(可用列 = RecipientID、FirstName、LastName、Address、City、Zip、Country、OrderID) ; 外键 = OrderID)
Orders 和 OrderRecipients 之间存在[一对多]关系。一份订单可以有多个收件人。
我正在尝试通过以下代码提取订单的收件人。
var allmyrecipients = from o in mycontext.Orders
where (o.SiteID.Equals("NYC") || o.SiteID.Equals("SFO"))
select o.OrderRecipients;
但是,当我尝试使用以下代码获取收件人的姓名时:
foreach (var recipient in allmyrecipients)
{
Console.WriteLine(recipient.FirstName);
}
收件人的名字和其他属性在智能感知下拉列表中不可用。我收到“不包含 FirstName 的定义”错误。
这是为什么?有什么补救措施?我在这里做错了什么?我正在使用 VS 2010、Entity Framework 4。
感谢您抽出时间来提供帮助。
Here is my problem with simplified example.
I have two entities modeled from SQL Server database:
- Orders (columns available = OrderID, PackageCount,ManufactureDate, ShipDate, StatusID) Primary Key = OrderID)
- OrderRecipients (columns available = RecipientID, FirstName, LastName, Address, City, Zip, Country, OrderID; Foreign Key = OrderID)
There is a [1 to many] relationship between Orders and OrderRecipients. One order can have several recipients.
I'm trying to extract the recipients of orders via the following code.
var allmyrecipients = from o in mycontext.Orders
where (o.SiteID.Equals("NYC") || o.SiteID.Equals("SFO"))
select o.OrderRecipients;
However when I try to get the names of the recipients with the following code:
foreach (var recipient in allmyrecipients)
{
Console.WriteLine(recipient.FirstName);
}
the FirstName and other attributes of the recipient are not available in the Intellisense drop-down. I get "does not contain a definition of FirstName" error.
Why is this and what is the remedy? What am I doing wrong here? I'm working with VS 2010, Entity Framework 4.
Thank you for taking time to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我将其重构为应该使用 SelectMany< 的东西/a>.试一试:
EDIT: I refactored this into somthing that should work using SelectMany. Give this a shot: