public static void ToDataTable <TModel>(this IList <TModel> list, DataTable dt) { var source = new MappingProviderForDataTable(dt); var target = new MappingProviderForCollection <TModel>(list); target.AssignTo(source); }
public static IList <TModel> ToDataModel <TModel>(this DataTable dt) { var list = new List <TModel>(); var source = new MappingProviderForDataTable(dt); var target = new MappingProviderForCollection <TModel>(list); source.AssignTo(target); return(list); }
public void DataTable_To_Collection_Mapping_test() { var dt = new DataTable(); var person = new List<MockPerson>(); person.Add(new MockPerson() { Name = "AAAA", Age = 1 }); person.Add(new MockPerson() { Name = "BBBB", Age = 2 }); person.Add(new MockPerson() { Name = "CCCC", Age = 3 }); var source = new MappingProviderForDataTable(dt); var target = new MappingProviderForCollection<MockPerson>(person); target.AssignTo(source); Console.WriteLine("DataTable rows count is " + dt.Rows.Count.ToString()); }
public void Mapping_DataTable_Assign_To_List() { var source = new DataTable(); source.Columns.Add("Name", typeof(string)); source.Columns.Add("Age", typeof(int)); source.Rows.Add("NCsoft 1", 11); source.Rows.Add("NCsoft 2", 2); source.Rows.Add("NCsoft 3", 3); var target = new List<MockPerson>(); var mapping1 = new MappingProviderForDataTable(source); var mapping2 = new MappingProviderForCollection<MockPerson>(target); mapping1.AssignTo(mapping2); foreach ( var person in target ) { TestContext.WriteLine("Name:{0}, Age:{1}", person.Name, person.Age); } }