Creating a List by combining two lists

c#

Solution

Instead of storing country id in your Customer class, just store the object itself. That is, make it like this:

public Class Customer
{
public int CustomerId {get;set;}
public string CustomerName {get;set}
public String Street {get;set}
public String Address {get;set}
public Country Country {get;set}
//...o
}

Then you have all the needed info in your `Customer` object, and there's no need to try to merge lists or anything like that.

On your `SQL` statement, join to country table and get the country name as part of the result set, then you can populate the customer list in one server round trip.

Problem

I am new to .Net. I have two objects, `Customer` and `Country` in my project : ``` public class Customer { public int CustomerId {get;set;} public string CustomerName {get;set} public String Street {get;set} public String Address {get;set} public int CountryId {get;set} //...o } public class Country { public int CountryId {get;set;} public String CountryName{get;set} } ``` I have two lists, `List<Customer>` and `List<Country>.` I am using a sql join statement to list customers with country. But I am confused how can I create a single list which contains customers along with the country name. Is it necessary to create separate class for that? Thanks in advance.

Original source