views:

228

answers:

0

Please see my code: var miportal = new AdventureWorksEntities();

    // one to many relationship
    var result = miportal.AddressType
        .Include("CustomerAddress")           
        .Where(at => at.CustomerAddress.Any(ca => ca.CustomerID == 3));

there are 2 tables; AddressType and CustomerAddress (1 CustomerAddress has only one AddressType and one AddressType can have many CustomerAddress)

The result of this query is that only 1 AddressType is returned which is expected, but CustomerAddress collection of that returned AddressType is not filtered.

There should be one CustomerAddress for this as the query needs but 701 CustomerAddress objects are returned which all have the CustomerID of 3.

How can I write the Where clause so that it only returns one CustomerAddress?