automapper

ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十五节--缓存小结与ABP框架项目中 Redis Cache的实现

痴心易碎 提交于 2020-07-28 20:51:44
返回总目录: ABP+AdminLTE+Bootstrap Table权限管理系统一期 缓存 为什么要用缓存 为什么要用缓存呢,说缓存之前先说使用缓存的优点。 减少寄宿服务器的往返调用(round-trips)。 如果缓存在客户端或是代理,将减少对服务器的请求,减少带宽。 减少对数据库服务器的往返调用(round-trips)。 当内容缓存在web服务器,能够减轻对数据库的请求。 减少网络带宽。 避免了重新生成可重用内容的时耗。 提高性能 因为缓存减少了round-trips, network traffic(网络带宽),并避免- 了生成可重用内容的时耗,所以对性能有巨大的提高。 传统的缓存方式 传统的缓存方式如下面这张图 之前我们处理方式处理起来也很简单 页面输出缓存,直接在 ASP.NET中页面缓存的使用OutputCache 在aspx页的顶部加这样一句即可: <%@ OutputCache Duration="60" VaryByParam="none" %> Duration 表示缓存的时间秒,必选,否则报错。 第二种方式 if (this.Cache["Keys"] == null) { this.Cache.Insert("Keys", List, null, DateTime.Now.AddHours(2), TimeSpan.Zero); }

从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之十二 || 三种跨域方式比较,DTOs(数据传输对象)初探

雨燕双飞 提交于 2020-07-27 10:11:43
本文3.0版本文章 https://mp.weixin.qq.com/s/KkcEN6VIVdPIEYIfKPs_Dw 更新反馈 1、博友@ 落幕残情 童鞋说到了,Nginx反向代理实现跨域,因为我目前还没有使用到,给忽略了,这次记录下,为下次补充。 此坑已填 2、提示:跨域的姊妹篇——《 三十三║ ⅖ 种方法实现完美跨域 》 代码已上传Github+Gitee,文末有地址   今天忙着给小伙伴们提出的问题解答,时间上没把握好,都快下班了,赶紧发布:书说上文《 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十一 || AOP自定义筛选,Redis入门 11.1 》,昨天咱们说到了分布式缓存键值数据库,主要讲解了如何安装,使用,最后遗留了一个问题,同步+Redis缓存还是比较简单,如何使用异步泛型存取Redis,还是一直我的心结,希望大家有会的,可以不吝赐教,本系列教程已经基本到了尾声,今天就说两个小的知识点,既然本系列是讲解前后端分离的,那一定会遇到跨域的问题,没错,今天将说下跨域!然后顺便说一下DTOs(数据传输对象),这些东西大家都用过,比如,在MVC中定义一个ViewModel,是基于Model实体类的,然后做了相应的变化,以适应前端需求,没错,就是这个,如果大型的实体类,一个个复杂的话会稍显费力,今天就是用一个自动映射工具——AutoMapper。

Automapper Expression mapping one property to many

江枫思渺然 提交于 2020-07-22 21:35:21
问题 I'm running a WebAPI, Asp.Net Core 3.1 Automapper: 9.0 Automapper.Extensions.ExpressionMapping: 3.1 My LocaleDto PK is a composite key of 2 FK - LanguageCode and CountryCode public class LocaleDto { [Key, ForeignKey(nameof(Language)), Column(Order = 0)] public string LanguageCode { get; set; } public LanguageDto Language { get; set; } [Key, ForeignKey(nameof(Country)), Column(Order = 1)] public string CountryCode { get; set; } public CountryDto Country { get; set; } } I would like to map

Automapper does not map properly null List member, when the condition != null is specified

点点圈 提交于 2020-07-18 05:12:07
问题 There is a problem when I try to map a null list (member) of an object, considering that I specified: .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null )); cfg.AllowNullCollections = true; // didn't help also short example from code: gi.PersonList = new List<Person>(); gi.PersonList.Add(new Person { Num = 1, Name = "John", Surname = "Scott" }); GeneralInfo gi2 = new GeneralInfo(); gi2.Qty = 3; Mapper.Map<GeneralInfo, GeneralInfo>(gi2, gi); gi.PersonList.Count =

Automapper does not map properly null List member, when the condition != null is specified

 ̄綄美尐妖づ 提交于 2020-07-18 05:11:19
问题 There is a problem when I try to map a null list (member) of an object, considering that I specified: .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null )); cfg.AllowNullCollections = true; // didn't help also short example from code: gi.PersonList = new List<Person>(); gi.PersonList.Add(new Person { Num = 1, Name = "John", Surname = "Scott" }); GeneralInfo gi2 = new GeneralInfo(); gi2.Qty = 3; Mapper.Map<GeneralInfo, GeneralInfo>(gi2, gi); gi.PersonList.Count =

EF6 Automapper Inheritance/Abstract Class Errors

Deadly 提交于 2020-07-10 11:33:06
问题 I'm building a .NET Web API using Entity Framework 6 with AutoMapper to map entities to DTOs. When I try to introduce an TPH (table per hierarchy) with an abstract base class, I get a very long and very useless (to me at least) error. The error is below, I'm not sure what the actual error is. I've tried Googling various sections of it to no avail. This is my mapping: Mapper.CreateMap<ParentClass, ParentClassDTO>() .Include<ClassA, ClassADTO>() .Include<ClassB, ClassBDTO>(); Mapper.CreateMap

EF6 Automapper Inheritance/Abstract Class Errors

妖精的绣舞 提交于 2020-07-10 11:32:58
问题 I'm building a .NET Web API using Entity Framework 6 with AutoMapper to map entities to DTOs. When I try to introduce an TPH (table per hierarchy) with an abstract base class, I get a very long and very useless (to me at least) error. The error is below, I'm not sure what the actual error is. I've tried Googling various sections of it to no avail. This is my mapping: Mapper.CreateMap<ParentClass, ParentClassDTO>() .Include<ClassA, ClassADTO>() .Include<ClassB, ClassBDTO>(); Mapper.CreateMap

Automapper - How to map from source child object to destination

馋奶兔 提交于 2020-07-08 14:53:48
问题 I am trying to map from a child object of source to destination(as parent object). Source Model: public class SourceBaseResponse<T> where T : new() { public string Type { get; set; } public string Id { get; set; } public T Attributes { get; set; } } For my example I am using T to be of type SourceAssignment public class SourceAssignment { public string Id { get; set; } public string Email { get; set; } public string EmployeeId { get; set; } public string FirstName { get; set; } public string

Skip mapping null properties

允我心安 提交于 2020-06-25 09:42:53
问题 I'm using AutoMapper to map a ViewModel to a Model. However, I want properties to not be mapped if the corresponding source property is null . My source class is as follows: public class Source { //Other fields... public string Id { get; set; } //This should not be mapped if null } And the destination class is: public class Destination { //Other fields... public Guid Id { get; set; } } And here is how I configured the mapper: Mapper.Initialize(cfg => { //Other mappings... cfg.CreateMap<Source

Mapping a list to a dictionary

一个人想着一个人 提交于 2020-06-17 13:20:08
问题 I have this class: class ClassFrom { public int Id { get; set; } public string Foo { get; set; } public string Bar { get; set; } } I want to map it into this, with the Id property becoming the dictionary's key: class ClassTo { public string Foo { get; set; } public string Bar { get; set; } } Dictionary<int, ClassTo> toDict = mapper.Map<List<ClassFrom>, Dictionary<int, ClassTo>>(fromList); Is there a recommended way to accomplish this? The best way I've found to do this using Automapper has a