AutoMapper使用示例(二)【常规的转换器和分页功能】

课程11:仓储层Repository实现、AutoMapper自动映射 本文是《.Net Core从零学习搭建权限管理系统》教程专栏的课程(点击链接,跳转到专栏主页,欢迎订阅,持续更新…)专栏介绍:以实战为线索,基于.Net 7 + REST + Vue、前后端分离,不依赖任何第三方框架,从零一步一步讲解权限管理系统搭建。专栏适用于人群:Web后端开发人员本课程内容:1、仓储层Repository实现2、Repository依赖注入3、AutoMapper使用方法4、AutoMapper依赖注入。 阅读详情

Model层模型如下:

    public class SrcEmployee
    {
        public string Name { get; set; }
        public string Age { get; set; }
        public string Status { get; set; }
        public DateTime HireDate { get; set; }
    }

    public class DestEmployee
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public EmployeeStatus Status { get; set; }
        public string HireDate { get; set; }
    }

   public interface IPagedList
    {
        int TotalCount { get; set; }
        int PageIndex { get; set; }
        int PageSize { get; set; }
        bool IsPreviousPage { get; }
        bool IsNextPage { get; }
    }
Program.cs代码如下:

  class Program
    {
        static void Main()
        {
             
            var srcEmp = new SrcEmployee
                             {
                                 Name = "天帝",
                                 Age = "244",
                                 Status = "离职",
                                 HireDate = Convert.ToDateTime("2010/2/1")
                             };


              List<SrcEmployee> srcEmpList =new List<SrcEmployee>();



              srcEmpList.Add(new SrcEmployee
              {
                  Name = "朱雀",
                  Age = "24",
                  Status = "在职",
                  HireDate = Convert.ToDateTime("2016/2/1")
              });

             srcEmpList.Add(new SrcEmployee {
                                 Name = "玄武",
                                 Age = "26",
                                 Status = "离职",
                                 HireDate = Convert.ToDateTime("2010/12/1")
                             });

              srcEmpList.Add(new SrcEmployee {
                                 Name = "青龙",
                                 Age = "24",
                                 Status = "离职",
                                 HireDate = Convert.ToDateTime("2015/2/11")
                             });

              srcEmpList.Add(new SrcEmployee {
                                 Name = "白虎",
                                 Age = "27",
                                 Status = "在职",
                                 HireDate = Convert.ToDateTime("2016/12/15")
                             });


            //Mapper映射器转换
            Mapper.CreateMap<string, int>().ConvertUsing(Convert.ToInt32);
            Mapper.CreateMap<DateTime, string>().ConvertUsing<CustomDateTimeConverter>();

            //SrcEmployee -> DestEmployee转换
            Mapper.CreateMap<SrcEmployee, DestEmployee>().ForMember(dest => dest.Status, opt => opt.ResolveUsing<EmployeeStatusResolver>());
            var destEmp = Mapper.Map<SrcEmployee, DestEmployee>(srcEmp);
            
            
            Console.WriteLine("名字:{0},年龄:{1},状态:{2},雇佣时间:{3}", destEmp.Name, destEmp.Age, destEmp.Status, destEmp.HireDate);

            Console.WriteLine("---------------------------------------------------------------------------");

            int pageSize = 3;
            int page = 0;
            IQueryable<SrcEmployee> posts = srcEmpList.OrderByDescending(p => p.HireDate).AsQueryable();
            PagedList<DestEmployee> pagedList = posts.ToPagedList<SrcEmployee, DestEmployee>(page, Mapper.Map<IEnumerable<SrcEmployee>, IEnumerable<DestEmployee>>, pageSize);

            pagedList.ToList().ForEach(delegate(DestEmployee de)
            {
                Console.WriteLine(de.Name+"受雇于:"+de.HireDate);
            });
            Console.ReadKey();

        }
  
    }
 public enum EmployeeStatus { Stay, Exit, LongHoliday } ;


    /// <summary>
    ///  DateTime -> string 
    /// </summary>
    public class CustomDateTimeConverter : TypeConverter<DateTime, string>
    {
        protected override string ConvertCore(DateTime source)
        {
            return source.ToString("yyyy年MM月dd日");
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class EmployeeStatusResolver : ValueResolver<SrcEmployee, EmployeeStatus>
    {
        protected override EmployeeStatus ResolveCore(SrcEmployee source)
        {
            switch (source.Status)
            {
                case "在职":
                    return EmployeeStatus.Stay;
                case "离职":
                    return EmployeeStatus.Exit;
                case "长期休假中":
                    return EmployeeStatus.LongHoliday;
                default:
                    throw new UnKnowonEmployeeStatusException();
            }
        }
    }

    public class UnKnowonEmployeeStatusException : Exception { }
PagedList.cs代码如下:

/// <summary>
    /// 使用AutoMapper PagedList的实现,从一个IQueryable发出视图模型。
     ///AutoMapper是没有明确要求,但创建映射器参数的最简单方法。
    /// </summary>
    /// <typeparam name="TSource">类型(模型)</typeparam>
    /// <typeparam name="TOutput">输出类型(视图模型)</typeparam>
    public class MappedPagedList<TSource, TOutput> : PagedList<TOutput>
    {
        /// <param name="source">IQueryable</param>
        /// <param name="index">从零开始的页面索引</param>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="mapper">映射函数,最容易使用AutoMapper创建</param>
        public MappedPagedList(IQueryable<TSource> source, int index, int pageSize, Func<IEnumerable<TSource>, IEnumerable<TOutput>> map)
            : base(index, pageSize, source.Count())
        {
            this.AddRange(map(source.Skip(index * pageSize).Take(pageSize).ToList()));
        }

        /// <param name="source">list</param>
        /// <param name="index">从零开始的页面索引</param>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="mapper">映射函数,最容易使用AutoMapper创建</param>
        public MappedPagedList(List<TSource> source, int index, int pageSize, Func<IEnumerable<TSource>, IEnumerable<TOutput>> map)
            : base(index, pageSize, source.Count())
        {
            this.AddRange(map(source.Skip(index * pageSize).Take(pageSize).ToList()));
        }
    }

    public class PagedList<T> : List<T>, IPagedList
    {
        public PagedList(IQueryable<T> source, int index, int pageSize)
            : this(index, pageSize, source.Count())
        {
            this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
        }

        public PagedList(List<T> source, int index, int pageSize)
            : this(index, pageSize, source.Count())
        {
            this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
        }

        protected PagedList(int index, int pageSize, int totalCount)
        {
            this.PageSize = pageSize;
            this.PageIndex = index;
            this.TotalCount = totalCount;
        }

        public int TotalCount { get; set; }
        public int PageIndex { get; set; }
        public int PageSize { get; set; }

        public bool IsPreviousPage { get { return (PageIndex > 0); } }
        public bool IsNextPage { get { return (PageIndex * PageSize) < TotalCount - PageSize; } }
    }

    public static class Pagination
    {
        public static PagedList<T> ToPagedList<T>(this IQueryable<T> source, int index, int pageSize = 10)
        {
            return new PagedList<T>(source, index, pageSize);
        }

        public static MappedPagedList<TSource, TOutput> ToPagedList<TSource, TOutput>(this IQueryable<TSource> source, int index, Func<IEnumerable<TSource>, IEnumerable<TOutput>> mapper, int pageSize = 10)
        {
            return new MappedPagedList<TSource, TOutput>(source, index, pageSize, mapper);
        }
    }
结果如图:






AutoMapper语法配源码总结 AutoMapper语法配源码总结,热心群友总结的,下载看详细总结 立即下载

相关推荐

Dto转实体类 AutoMapper

AutoMapper工具的使用 Dto 与 实体类 的值相互转换

ASP.NET Core Web中使用AutoMapper进行对象映射

在日常开发中,我们常常需要将一个对象映射到另一个对象,这个过程中可能需要编写大量的重复性代码,如果每次都手动编写,不仅会影响开发效率,而且当项目越来越复杂、庞大的时候还容易出现错误。为了解决这个问题,对象映射库就随之而出了,这些库可以自动完成对象之间的映射,从而减少大量的开发工作量,提高开发工作效率。今天我们来讲讲在ASP.NET Core Web中使用AutoMapper快速进行对象映射。

专注于C#/.NET/.NET Core学习、工作、面试干货和实战教程分享。这里聚焦了大量的C#/.NET/.NET Core优质文章、开源项目、实用工具和学习、工作、面试心得。 1242

使用AutoMapper实现Dto和Model的自由转换(下)

NULL 博文链接:https://zz8ss5ww6.iteye.com/blog/1126330

ASP.NET Identity “角色-权限”管理 9

1.1. 对象映射 参考1:https://github.com/AutoMapper/AutoMapper 参考2:AutoMapper的配置方法 参考3:使用AutoMapper实现Dto和Model的自由转换(上) 为适应View的变化,将数据封装到ViewModel,从而保持领域模型的纯净稳定,这里使用AutoMapper处理Model与ViewModel之间映射...

weixin_30583563的博客 172

AutoMapper的使用

1.包含AutoMapper.dll 在工程的Lib文件夹下 2.AutoMapper用法 - Qi Fei - 博客园.png 参考图片 3.工程为简单的代码演示,有注释,请大家参考

AutoMapper映射配置和使用实例运用。

AutoMapper的引用,AutoMapper的映射配置,AutoMapper的自动映射和例外映射使用实例。

AutoScraper——爬虫神器

AutoScarper爬虫神器

HJ_blog 1966

在 dell precision 7920 tower CentOS 8 Stream 上安裝nvidia驱动程序、Anaconda

简单记录一下如何在实验室dell precision 7920 tower CentOS 8 Stream上安装nvidia显卡驱动。

chen9046的博客 992

使用AutoMapper将复杂对象映射到对象列表

在这篇文章中,我们将重点介绍将复杂对象转换为对象列表。

寒冰屋的专栏 1791

知识图谱中的 Ontology(本体论)

本文的部分图片和内容来自中国科学院自动化研究所刘康老师的课件 Ontology(本体论) Ontology 是(特定领域)信息组织的一种形式,是领域知识规范的抽象和描述,是表达、共享、重用知识的方法。 Ontology 是知识体系构建的关键技术,知识图谱是一种人工智能技术,它的关键在于让计算机能够处理人类的知识。然而,人类脑海中的知识通常是直觉性的,我们无法将这种直觉性的知识直接输入给计算机,On...

P01son的博客 2万+

LABVIEW学习之MODBUS-TCP通讯

LABVIEW学习之MODBUS-TCP通讯 1,MODBUS-TCP通讯介绍: MODBUS通讯是工业上面经常用到的一种通讯协议。该协议的原理及介绍不在此累述,下面直接介绍LABVIEW对此协议的应用。 2,MODBUS通讯所需的函数: 安装了DSC模块之后可以在数据通信内找到相关函数 3 ,主VI 主要思路就是使用状态机来进行连接 读取 写入 断开。使用枚举类型来选择状态: 1,连接 2,写入多个M继电器: 3,写入单个M继电器 4,写入双字节D...

风动9527的博客 2万+

AutoMapper 使用总结

AutoMapper是干什么用的? AutoMapper 是一个用在.Net平台上的对象到对象的自动化映射工具。可将一种类型的对象自动转换到另一种类型的对象。 例如将Model对象和DTO对象之间互转操作。 怎么安装使用 可以使用Nuget包工具搜索“AutoMapper”进行安装使用。 官方网站 https://automapper.readthedocs.io/en/latest/...

cangyue080180的专栏 910

手把手教你用TLP350驱动IGBT:光耦隔离驱动电路完整设计教程

本文详细介绍了如何使用TLP350光耦隔离驱动电路设计IGBT驱动方案。从TLP350芯片特性分析到驱动电路架构设计,包括信号调理、自举电源和栅极控制网络,再到PCB布局优化和保护电路设计,提供了完整的实战指南。通过实测波形分析和故障排查,帮助工程师快速掌握IGBT驱动电路的设计要点和进阶技巧。

weixin_30566063的博客 822

java automapper 使用_AutoMapper实际项目运用

AutoMapper是对象到对象的映射工具。在完成映射规则之后,AutoMapper可以将源对象转换为目标对象。配置AutoMapper映射规则AutoMapper是基于约定的,因此在实用映射之前,我们需要先进行映射规则的配置。public class Source{public int SomeValue { get; set; }public string AnotherValue { get...

weixin_29483167的博客 419

DFT实战:如何用Synopsys工具搞定多时钟域Scan Chain设计(附避坑指南)

本文详细解析了使用Synopsys DFT Compiler工具链实现多时钟域Scan Chain设计的全流程,包括时钟混合策略、跨时钟域平衡技巧和实战脚本剖析。通过量产验证的工程实践方案,帮助DFT工程师有效解决复杂SoC设计中的Scan Chain挑战,提升测试效率和质量。

mm9012的博客 1031

交换芯片数据通路四大核心微架构深度解析

数据通路是交换芯片性能的物理根基,决定着低延迟、高吞吐与突发承载能力。其本质是在硅片约束下对带宽、时序、功耗与统计复用的系统性权衡。Crossbar提供确定性低延迟但受RC延迟与功耗制约;VOQ通过虚拟队列隔离输出争抢,却引入仲裁复杂度与内存开销;Shared Buffer依托统计复用提升缓存利用率,但面临碎片化与管理策略挑战;Cell Fabric以固定长度cell重构交换粒度,在AI与金融等小包敏感场景实现尾延迟稳定。这些架构并非替代关系,而是面向不同网络不确定性(如流量不对称性、突发强度、包长分布)的

weixin_32667955的博客 188

java automapper 使用_AutoMapper用法(转载)

申明作者:齐飞配置AutoMapper映射规则AutoMapper是基于约定的,因此在实用映射之前,我们需要先进行映射规则的配置。1 public classSource2 {3 public int SomeValue { get; set; }4 public string AnotherValue { get; set; }5 }67 public classDestinat...

weixin_42415498的博客 770

【Cadence】stb仿真和ac仿真——以一个简单的全差分反相放大器仿真为例

最近在补一些仿真方法学的问题,以及一些一直以来都有点模糊的概念,简单记录一下。搭建一个以两个CMOS反相器构成的全差分放大器(28nm工艺,PMOS和NMOS尺寸一致)激励的设置方便共模和差模仿真用同一个TB(这里有一个问题:这个放大器需要在开环下仿真还是闭环下?哪些放大器应用在开环,哪些闭环?这种应用场景不同会导致需要仿真得到开环还是闭环增益,或者环路增益?(我知道放大器在设计的时候肯定都是闭环应用的多,但是什么时候没必要闭环应用?光验证ac和stb仿真是否一样的话有必要有回路吗?

weixin_44951108的博客 5万+

对象到对象映射-AutoMapper

AutoMapper 是一个对象-对象映射器,可以将一个对象映射到另一个对象。 用来解决一个看似复杂的问题,这种类型的代码编写起来相当枯燥乏味, 官网地址: http://automapper.org/ 官方文档: https://docs.automapper.org/en/latest/ 入门 AutoMapper支持使用静态服务位置构造“自定义值解析器”,“自定义类型转换器”和“值转换器”的功能: var configuration = new MapperConfiguration

https://github.com/conanl5566 299

Python 爬虫实战:抓取应届生求职网校招岗位信息,助力学子就业

应届生求职网作为国内知名的招聘平台,汇聚了大量企业的校招岗位信息。了解这些岗位信息,对于应届毕业生制定求职策略、企业制定招聘计划以及相关就业市场分析等都具有重要意义。因此,本文将深入探讨如何运用 Python 爬虫技术从应届生求职网平台抓取校招岗位信息,为应届毕业生提供有益的就业信息支持。本文深入探究了利用 Python 爬虫技术从应届生求职网平台抓取校招岗位信息的全流程。从前期的环境搭建、模拟登录,到核心的数据抓取、存储,再到后续的数据分析与可视化,都详细展开讲解并提供代码支持。

u014481728的博客 1300

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

AutoMapper官方文档(二)【升级指南】

初始化 您现在必须使用Mapper.Initialize或new MapperConfiguration()来初始化AutoMapper。如果您希望保持静态使用,请使用Mapper.Initialize。 如果你有很多的Mapper.CreateMap调用,把它们移动到一个Profile,或者Mapper.Initialize,在启动时调用一次。 例如在这里看到。 Profile...

dichu8371的博客 311

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

.net core使用AutoMapper

AutoMapper文档:http://docs.automapper.org/en/stable/The-MyGet-build.html 新的版本抛弃了静态API方法,我们将使用依赖注入来完成。 ①添加包 ②创建MyAutoMapper.cs文件来创建实体和Dto之间的映射关系 public class MyAutoMapper : Profile { ...

weixin_30821731的博客 157

AutoMapper用法

AutoMapper是对象到对象的映射工具。在完成映射规则之后,AutoMapper可以将源对象转换为目标对象。 配置AutoMapper映射规则 Profile的用法 扁平化映射(Flattening) 指定映射字段(Projection) 验证配置项(Configuration Validation) 自定义解析器(Custom value resolvers) 自定义类型转换器(Custo...

Vincent_yuan1991的博客 613

关于AutoMapper

AutoMapper 是一个基于约定的对象 - 对象映射库,主要用于在不同对象类型之间自动映射属性值。它能根据配置的映射规则,将源对象的属性值填充到目标对象中,避免了手动编写大量繁琐的对象映射代码。

ly1h1的博客 1579
上一篇: ASP.NET MVC4下使用MongoDB实现时间戳和ObjectId相互转换
下一篇: Zookeeper.NET Client (一)【自己编写客户端 连接实例】
.NET跨平台
博客等级 码龄15年 6066粉丝 738原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值