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.
EDIT: I refactored this into somthing that should work using SelectMany. Give this a shot: