我遇到了以下linq查詢的問題。在linq查詢中分配IEnumerable列表
public class Address
{
public int addressID { get; set; }
public string address { get; set; }
}
public class AdvanceClient
{
public int ClientID { get; set; }
public string Name { get; set; }
public string Mobile { get; set; }
public IEnumerable<Address> Addresses { get; set; }
}
在下面的linq查詢中,我想將IEnumerable地址列表分配給Addresses屬性。我在tblAdvanceClient和tblAddress表之間有一對多的關係。
IEnumerable<AdvanceClient> addcli = from tbcli in dc.tblAdvanceClients
join tbadd in dc.tblAddresses
on tbcli.AddressID equals tbadd.AddressID
select new AdvanceClient
{
ClientID = tbcli.ClientID,
Company = tbcli.Company,
Fax = tbcli.Fax,
Mobile = tbcli.Mobile,
Name = tbcli.Mobile,
Telephone = tbcli.Telephone,
Addresses = new Address { } // Here i need to get the list of address to each client
};
怎麼能一個客戶端有多個一個地址,如果地址和客戶端表具有一對一的關係(Client.ClinetID - Client.AddressID - > Address.AddressID)? –