Reputation: 129
Let's say I have three generic lists of the diffrent type Customer, Address and Account. How do I combine them into one generic list of 'CustomerProfile' type?
Example:
Public class Customer
{
long customerId{ get; set; }
int titleId{ get; set; }
string firstName{ get; set; }
string middleName{ get; set; }
int maritalStatusId { get; set; }
}
public class Address
{
public long addressId{ get; set; }
long customerId{ get; set; }
short addressTypeId{ get; set; }
string postCode{ get; set; }
string geoCodeLattitude{ get; set; }
string geoCodeLongitude{ get; set; }
}
public class Account
{
long accountID{ get; set; }
string accountDesc{ get; set; }
short accountStatusID{ get; set; }
DateTime joinDate{ get; set; }
DateTime insertDateTime{ get; set; }
}
when I return new CustomerProfile list the result set should be look like below:
<CustomerProfile>
<Customer>
<customerId>
<titleId>
<firstName>
<middleName>
<maritalStatusId>
</Customer>
<Address>
<addressId>
<customerId>
<addressTypeId>
<postCode>
<geoCodeLattitude>
<geoCodeLongitude>
</Address>
<Account>
<accountID>
<accountDesc>
<accountStatusID>
<joinDate>
<insertDateTime>
</Account>
</CustomerProfile>
Upvotes: 0
Views: 468
Reputation: 2967
You have three Entities as you said Customer, Address and Accounts. Your two entites Customer and Address have association but Accounts doesnt have any association, it means it can hold all Account data from Account table in that Entity say List.
First you can create a property as a list in the customer class for holding its addresses. Second you can define another property as a list for accounts.
When you load the application then you can get all the customers and their address and the fill the Cusotmer object and its Address property and Account into it.
Now, when you get the object of customer then by its two properties Address and Account you can access its data easily.
You can also make a class CustomerProfile in which you can define your all entities as a list and then when you run your applicatoin then you can fill all their properties to access the object of customer profile.
Upvotes: 0
Reputation: 12904
Short answer, you can't.
You will need to use List<object>
to store them all or create a CustomerProfile
class that encapsulates Customer/Address/Account.
public class CustomerProfile
{
public Customer { get; set;}
public Address { get; set;}
public Account { get; set:}
}
Then you can have
List<CustomerProfile>
Upvotes: 1