AutoMapper,对象映射的简单使用
using AutoMapper;
using AutoMapper.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace AutoMapperTest
{
class Program
{
static void Main(string[] args)
{
//传统方法,手动写好对应的映射关系
//Mapper.Initialize(p => p.CreateMap<Source, Destination>()); //下面的写法就不用一一指定映射关系了
Mapper.Initialize(new MapperConfigurationExpression
{
}); Source src = new Source()
{
SomeValue = ,
AnotherValue = "xxx",
StringList = new List<string>() { "aa", "bb", "cc" },
IntList = new List<int>() { , , },
StudentList = new List<Student>() { new Student() { Name = "jeff1", Age = }, new Student() { Name = "jeff2", Age = } }
};
Destination dest = Mapper.Map<Destination>(src); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(dest));
Console.ReadLine();
}
} public class Source
{
public int SomeValue { get; set; }
public string AnotherValue { get; set; }
public List<string> StringList { get; set; }
public List<int> IntList { get; set; }
public List<Student> StudentList { get; set; }
} public class Destination
{
public int SomeValue { get; set; }
public string AnotherValue { get; set; }
public List<string> StringList { get; set; }
public List<int> IntList { get; set; }
public List<Student> StudentList { get; set; }
} public class Student
{
public string Name { get; set; }
public int Age { get; set; }
}
}
AutoMapper,对象映射的简单使用的更多相关文章
- .NET之AutoMapper对象映射工具运用
AutoMapper对象映射工具:主要是将某一个实体转成另一个实体. 1.引用NuGet包;搜索:AutoMapper 2.创建实体类 using System; using System.Colle ...
- .NetCore学习笔记:四、AutoMapper对象映射
什么是AutoMapper?AutoMapper是一个简单的小型库,用于解决一个看似复杂的问题 - 摆脱将一个对象映射到另一个对象的代码.这种类型的代码是相当沉闷和无聊的写,所以为什么不发明一个工具来 ...
- 【转】AutoMapper对象映射
什么是AutoMapper?AutoMapper是一个简单的小型库,用于解决一个看似复杂的问题 - 摆脱将一个对象映射到另一个对象的代码.这种类型的代码是相当沉闷和无聊的写,所以为什么不发明一个工具来 ...
- EF架构~AutoMapper对象映射工具简化了实体赋值的过程
回到目录 AutoMapper是一个.NET的对象映射工具,一般地,我们进行面向服务的开发时,都会涉及到DTO的概念,即数据传输对象,而为了减少系统的负载,一般我们不会把整个表的字段作为传输的数据,而 ...
- ASP.NET MVC 模型和数据对象映射实践
在使用 MVC 开发项目的过程中遇到了个问题,就是模型和数据实体之间的如何快捷的转换?是不是可以像 Entity Framework 的那样 EntityTypeConfiguration,或者只需要 ...
- 对象映射工具AutoMapper介绍
AutoMapper是用来解决对象之间映射转换的类库.对于我们开发人员来说,写对象之间互相转换的代码是一件极其浪费生命的事情,AutoMapper能够帮助我们节省不少时间. 一. AutoMapper ...
- 一文为你详细讲解对象映射库【AutoMapper】所支持场景
前言 在AutoMapper未出世前,对象与对象之间的映射,我们只能通过手动为每个属性一一赋值,时间长了不仅是我们而且老外也觉得映射代码很无聊啊.这个时候老外的所写的强大映射库AutoMapper横空 ...
- ASP.NET Core 中的对象映射之 AutoMapper
目录 AutoMapper 简介 AutoMapper 使用 初始化 Profile设置 扁平化映射 集合映射 投影 条件映射 值转换 设置转换前后行为 配置验证及设置 反向映射 自定义转换器 自定义 ...
- ASP.NET CORE 中使用AutoMapper进行对象映射
ASP.NET CORE 中使用AutoMapper进行对象映射 1.什么是AutoMapper? AutoMapper是基于对象到对象约定的映射工具,常用于(但并不仅限制于)把复杂的对象模型转为DT ...
随机推荐
- 082 HBase的几种调优(GC策略,flush,compact,split)
一:GC的调优 1.jvm的内存 新生代:存活时间较短,一般存储刚生成的一些对象 老年代:存活时间较长,主要存储在应用程序中生命周期较长的对象 永久代:一般存储meta和class的信息 2.GC策略 ...
- IPv6升级改造包括什么?
关于IPv6技术升级具体做了什么,在我脑海里只是更换了域名解析的IP而已,所以找了这篇文章,帮助初步解惑. 原文地址:https://www.maczd.com/post/web-ipv6-upgra ...
- flask 模板block super()的讲解
Flask强大的地方就可以引用模板,而且非常方便. 这里不得不介绍block这个概念. 模板的文件一般放在templates文件夹下,我们这里新建一个HTML文件,存放模板,'base.html' 在 ...
- 潭州课堂25班:Ph201805201 并发(进程与线程池) 第十四课 (课堂笔记)
循环执行一个线程 # -*- coding: utf-8 -*- # 斌彬电脑 # @Time : 2018/7/20 0020 5:35 import threading import queue ...
- 潭州课堂25班:Ph201805201 第五课:格式化输出和深浅复制 (课堂笔记)
格式化输出和字符串转义 占位符 使用示意 作用 %s '%s %s' % ('hello', 'world') 表示占位的是str %d '%d %d' % (1, 2) 表示占位的是int %d ' ...
- NOIP 2006 作业调度方案
[问题描述] 我们现在要利用m台机器加工n个工件,每个工件都有m道工序,每道工序都在不同的指定的机器上完成.每个工件的每道工序都有指定的加工时间. 每个工件的每个工序称为一个操作,我们用记号j-k表示 ...
- only_full_group_by的注意事项
only_full_group_by的注意事项 使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行
- WPF应用Access数据库
WPF应用Access数据库 现在Access数据库中有表GuestTable,其中的字段如下图所示,现在需要应用WPF技术为此表制作一个数据库管理窗口,实现对此数据库中的数据进行数据的增.删.改和查 ...
- Oracle 拼接列数据的方法
select wm_concat(fphone) phone from dq_phone_ndtbdxz wm_concat(列名):把多列值,合并成一列,用,隔开.
- JSP_tomcat_mysql_注冊验证用户;
本文出自:http://blog.csdn.net/svitter 资源下载: github: git clone https://github.com/Svtter/JSP-tomcat-mysql ...