I have 2 tables: Customer And Customer_Address
I have a function:
public IEnumerable<Customer_Address> ReadAddressForCustomer(int CustomerID)
{
ProjectServiceForCustomerDataContext DB = new ProjectServiceForCustomerDataContext();
var CA = (from C in DB.Customer_Addresses
join cust in DB.Customers
on C.CustomerID equals cust.ID
where C.CustomerID == CustomerID
select new
{
CustomerName=cust.Name,
CustomerAddress=C.Address,
CustomerTel=C.Telephone
}).ToList();
return CA;
}
But the CA is not a IEnumerable(Customer_Address) because it has Customer field (cust.Name)
How can I solve this problem ?
The solution that @Daniel DiPaolo suggest is good one, in which he declares a light class to hold the only properties you want, but I think it is better to use properties rather than fields, as below :