Attributes of an entity not available in LINQ to Entities

Here is my problem with simplified example.

I have two entities modeled from SQL Server database:

  1. Orders (columns available = OrderID, PackageCount,ManufactureDate, ShipDate, StatusID) Primary Key = OrderID)
  2. 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)

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:

var orders = from o in mycontext.Orders
    where (o.SiteID.Equals("NYC") || o.SiteID.Equals("SFO"))
    select o;

foreach (var recipient in orders.SelectMany(r => r.OrderRecipients)) 

Need Your Help

Display EditText value in another TextView after edit

android textview android-edittext

I have an EditText where the user inputs a string. After edit, the string is displayed in a TextView. I created a custom class called TextValidator which implements TextWatcher, to satisfy the

Problems with video streaming site for iPhone

iphone html video streaming mp4

I have been trying to embed some videos on a website I am building, and have come across a snag when trying to stream the videos to iPhone/iPad.