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 ...
随机推荐
- 关于Maven打包Java Web项目以及热部署插件Jrebel的使用
Java Web/Eclipse/Maven/Tomcat 最近有个新项目是java web项目,记录一下,可能比较乱.虽然没接触过Java,但是eclipse还是用过的 初识项目 同事说,项目是ma ...
- UC浏览器中Ajax请求中传递数据的一个坑
今天突然收到一个bug,有用户在其浏览器环境中一直无法提交内容,使用的是UC浏览器.当换成Chrome时,内容能够正常提交.鉴于本地没有一直使用Firefox 以及Chrome,于是去下载了一个UC ...
- Shiro笔记(五)JSP标签
Shiro笔记(五)JSP标签 导入标签库 <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags&q ...
- angular.js--demo2-----声明局部控制器controller
<!doctype html><html ng-app="HelloAngular"> <head> <meta charset=&quo ...
- 移动端html页面优化
对于访问量大的网站来说,前端的优化是必须的,即使是优化1KB的大小对其影响也很大,下面来看看来自ISUX的米随随讲讲移动手机平台的HTML5前端优化,或许对你有帮助和启发. 概述 1. PC优化手段在 ...
- only_full_group_by的注意事项
only_full_group_by的注意事项 使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行
- Activex控件的IObjectSafety接口问题
我的05年做流氓插件的时候,就注意到了这个问题,只要注册表加入 类似的就可以 HKEY_CLASSES_ROOT\Component Categories\{7DD95801-9882-11C ...
- EBS MOAC
alter session set nls_language='SIMPLIFIED CHINESE';alter session set nls_language ='AMERICAN'; exec ...
- Google+ 团队的 Android UI 测试
https://github.com/bboyfeiyu/android-tech-frontier/tree/master/android-blog/Google%2B%20%E5%9B%A2%E9 ...
- Fragment的可见再载入的方法(真正的Fragment的OnResume和OnPause)
一 起因 我们在做应用的过程中,一个应用的界面可能是多个Fragment切换而成的.可是如果在每次应用启动的时候就去载入大量的网络数据(如果你的每一个Fragment都须要载入网络数据.你也能够理解为 ...