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 ...
随机推荐
- Tr A HDU1575
矩阵基本算法 #include<cstdio> using namespace std; int n; struct matrix { int m[15][15]; }ans,base; ...
- Spring任务调度实战之Quartz Simple Trigger(转)
启动时执行和定时执行: 本文地址:http://blog.csdn.net/kongxx/article/details/6751300 在spring中对任务调度的集成除了使用JDK自带的Time ...
- POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)
题目链接:https://vjudge.net/contest/217847#problem/A 题目大意: 现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每 ...
- Mybatis Generator xml格式配置
Mybatis Generator可以使用Maven方式和Java方法,使用Maven这里是配置文件: <?xml version="1.0" encoding=" ...
- 新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial
新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial 作者:韩梦飞沙 Auth ...
- win10 设置
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha ============
- yum 安装 jenkins
环境:已安装 tomcat 安装(如果yum下载速度比较忙可以下载下来再安装) yum -y install https://pkg.jenkins.io/redhat/jenkins-2.77-1. ...
- vscode使用wsl调试代码
第一步在WSL中配好环境 第二步安装CodeRunner即可,在用户配置中加入如下行: "terminal.integrated.shell.windows": "C:\ ...
- CentOS下创建网桥
说明:以下创建的是永久网桥,即重启后依然生效. 0.安装网桥的依赖 yum -y install tunctl bridge-utils 1.创建网桥配置文件 UUID=`uuidgen` cat & ...
- android fastjson 解析
JSONObject jsonObject = JSON.parseObject(wsResponse);String recommends = jsonObject.getString(" ...