I have to classes –
public class Agent
{
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Thana { get; set; }
public int District { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string NID { get; set; }
public bool IsDeleted { get; set; }
public string AddedBy { get; set; }
public System.DateTime DateAdded { get; set; }
public string UpdatedBy { get; set; }
public Nullable<System.DateTime> DateUpdated { get; set; }
}
public class AgentModel
{
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Thana { get; set; }
public int District { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string NID { get; set; }
public bool IsDeleted { get; set; }
public string AddedBy { get; set; }
public DateTime DateAdded { get; set; }
public string UpdatedBy { get; set; }
public DateTime DateUpdated { get; set; }
}
How to convert one type of generic list to another type of generic list in C#?
For example - I want to convert list to list2.
List<agent> list = new List<agent>();
List<agentmodel> list2 = new List<agentmodel>();
And, how I can convert one object to another type of object?
For instance, I want to convert also Agent to agent2.
Agent agent = new Agent();
AgentModel agent2 = new AgentModel();
The main problem is my project already developed based on SQL server, and factory pattern is being used in my project. That's why, i just want to change only DataAccessManager class. Moreover, we named all model classes after all data table name (i.e for data table named Agent, the class name is AgentModel; for the data table product, the class name is ProductModel). However, my management wanted to use Entity Framework. As a result, i have followed DB first approach as i already have data tables. However, problem is that EF generate classes with the same name of data tables. Thus, the conversion is required. So, is there any way to name EF classes as like existing classes? or what should be the best solution?
Thanks in advance.