/// <summary> /// 测试一个新增的操作. /// </summary> public void DoTest1() { TestUiClass uiClass = new TestUiClass() { ID = 2, Name = "测试2", IsActive = true, }; // 测试将其转换为 UI 上使用的类. // 这里增加了一个 opts 的参数, 用于在 映射期间, 进行调用的处理. TestDbClass dbClass = Mapper.Map <TestUiClass, TestDbClass>( source: uiClass, opts: opt => { opt.AfterMap((src, dest) => dest.CreateTime = DateTime.Now); } ); Console.WriteLine("UI to DB......"); Console.WriteLine("UI类 = {0}", uiClass); Console.WriteLine("DB类 = {0}", dbClass); Console.WriteLine("UI to DB finish!!!"); }
public void DoTest() { // 先 手动 模拟一个 从数据库中获取的类. TestDbClass dbClass = new TestDbClass() { ID = 1, Name = "测试", IsActive = true, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, CreateUser = "******", LastUpdateUser = "******", }; // 测试将其转换为 UI 上使用的类. TestUiClass uiClass = Mapper.Map <TestDbClass, TestUiClass>(dbClass); Console.WriteLine("DB to UI......"); Console.WriteLine("DB类 = {0}", dbClass); Console.WriteLine("UI类 = {0}", uiClass); Console.WriteLine("DB to UI finish!!!"); }
/// <summary> /// 测试一个更新的操作. /// </summary> public void DoTest2() { // 先 手动 模拟一个 从数据库中获取的类. TestDbClass dbClass = new TestDbClass() { ID = 3, Name = "测试3", IsActive = true, CreateTime = DateTime.Now.AddSeconds(-2), LastUpdateTime = DateTime.Now.AddSeconds(-2), CreateUser = "******", LastUpdateUser = "******", sys_user_code = "Test", }; // 这里模拟 画面上, 更新了数据. TestUiClass uiClass = new TestUiClass() { ID = 3, Name = "测试3x7=21", IsActive = false, SysUserCode = "测试命名方式", }; // 注意: // 前面的 DoTest1 中的处理, 是 通过 ui 类, 创建一个 db 类. // 这里的处理, 是通过 ui 类, 更新 db 类. Mapper.Map(uiClass, dbClass); Console.WriteLine("UI to DB......"); Console.WriteLine("UI类 = {0}", uiClass); Console.WriteLine("DB类 = {0}", dbClass); Console.WriteLine("UI to DB finish!!!"); }
/// <summary> /// 测试一个新增的操作. /// </summary> public void DoTest1() { TestUiClass uiClass = new TestUiClass() { ID = 2, Name = "测试2", IsActive = true, }; // 测试将其转换为 UI 上使用的类. TestDbClass dbClass = Mapper.Map <TestUiClass, TestDbClass>(uiClass); Console.WriteLine("UI to DB......"); Console.WriteLine("UI类 = {0}", uiClass); Console.WriteLine("DB类 = {0}", dbClass); Console.WriteLine("UI to DB finish!!!"); }