automapper

How use profiles from nartc/automapper into a nestjs application

橙三吉。 提交于 2020-06-16 17:16:08
问题 I'm trying to use AutoMapper for nodejs from nartc/automapper lib inside a NestJS project, but I'm having troubles when trying to use Profiles functionality. Here is my configuration: App.module @Module({ imports: [ AutomapperModule.withMapper(), ], controllers: [], providers: [], }) export class AppModule implements NestModule {} Profile @Profile() export class RoleProfile extends ProfileBase { constructor(@InjectMapper() mapper: AutoMapper) { super(); mapper .createMap(Role,

How use profiles from nartc/automapper into a nestjs application

妖精的绣舞 提交于 2020-06-16 17:15:08
问题 I'm trying to use AutoMapper for nodejs from nartc/automapper lib inside a NestJS project, but I'm having troubles when trying to use Profiles functionality. Here is my configuration: App.module @Module({ imports: [ AutomapperModule.withMapper(), ], controllers: [], providers: [], }) export class AppModule implements NestModule {} Profile @Profile() export class RoleProfile extends ProfileBase { constructor(@InjectMapper() mapper: AutoMapper) { super(); mapper .createMap(Role,

Mapping string to List<string> and vice versa using Automapper

♀尐吖头ヾ 提交于 2020-05-29 02:32:33
问题 Basically I have this class which represents 1:1 with my database public class User { public int UserID { get; set; } public string Username { get; set; } public string Role { get; set; } } and I have this viewmodel public class UserEditViewModel { public UserEditViewModel() { Roles = new List<string>(); } public int UserID { get; set; } [Required] public string Username { get; set; } [Required] public List<string> Roles { get; set; } } I have no idea how to map between these 2. My current

Mapping string to List<string> and vice versa using Automapper

戏子无情 提交于 2020-05-29 02:29:29
问题 Basically I have this class which represents 1:1 with my database public class User { public int UserID { get; set; } public string Username { get; set; } public string Role { get; set; } } and I have this viewmodel public class UserEditViewModel { public UserEditViewModel() { Roles = new List<string>(); } public int UserID { get; set; } [Required] public string Username { get; set; } [Required] public List<string> Roles { get; set; } } I have no idea how to map between these 2. My current

AutoMapper generic conversion

会有一股神秘感。 提交于 2020-05-27 11:49:05
问题 I've been using AutoMapper and would like to take generic conversion one step further; instead of saying something like cfg.CreateMap<Container<int>, int>() .ConvertUsing(new ContainerConverter<Container<int>, int>()); I would rather set the AutoMapper to know how to map any Container, such as: cfg.CreateMap<Container<T>, T>() .ConvertUsing(new ContainerConverter<Container<T>, T>()); Since all conversions from Container to T are the same, it would be pointless to re-define this conversion for

Replacing empty strings with nulls with AutoMapper

我们两清 提交于 2020-05-15 03:38:53
问题 I am using AutoMapper to map DTOs to entities. Also, my WCF services are being consumed by SAP. The issue is that SAP sends me empty strings instead of nulls (that is, "" instead of null ). So I basically need to go through every field of the DTO I am receiving, and replace empty strings by nulls. Is there an easy way to accomplish this with AutoMapper? 回答1: Depends on what you are after - if there are string fields for which you would like to preserve the empty string and not convert to null

Replacing empty strings with nulls with AutoMapper

点点圈 提交于 2020-05-15 03:36:16
问题 I am using AutoMapper to map DTOs to entities. Also, my WCF services are being consumed by SAP. The issue is that SAP sends me empty strings instead of nulls (that is, "" instead of null ). So I basically need to go through every field of the DTO I am receiving, and replace empty strings by nulls. Is there an easy way to accomplish this with AutoMapper? 回答1: Depends on what you are after - if there are string fields for which you would like to preserve the empty string and not convert to null

.NetCore2.1项目升级到.NetCore3.1的一点记录

∥☆過路亽.° 提交于 2020-05-02 04:48:46
前言 最近将近半个月没有更新博客了,因为找到了新的工作,开始上班了。上班之余也没闲着,上周末将自己去年的一个.NetCore2.1的框架升级到了3.1版本。在升级过程中还是出现了不少问题。有些是版本升级必须要解决的,有些是因为自己犯了强迫症,一定要将引用的Nuget包升级到当前最新版本。 这里就凭借记忆,记录下这次升级的点点滴滴吧。 框架引用的Nuget包 这里先将引用到的部分Nuget包罗列出来,都是常用的库。 Autofac AutoMapper NewLife.Redis NLog System.Text.Json Microsoft.AspNet.SignalR DotNetCore.NPOI Quartz Swashbuckle.AspNetCore 升级到.NetCore 3.1出现的几个明显的问题 使用第三方IOC容器方式的改变导致依赖注入这一块代码需要改动 Startup内提供内置的依赖注入服务有所改变,导致原有的部分方法编译可通过运行时则异常 跨域实现部分微软做了更细化的限制,原有的跨域部分代码运行时异常 依赖的组件出现的问题 AutoMapper升级到9.0后因为官方移除了静态API导致所有引用到AutoMapper映射的地方都要改,同时需要将IMapper注入到DI容器内 Swashbuckle.AspNetCore升级到5.1后API有所更新

.Net下几种ORM

旧街凉风 提交于 2020-04-27 10:51:58
  最近研究了下ORM工具。总结一下。   之前有个小项目基于.Net40的WinForm。升级改造,想用ORM,由此引起。   第一选择是SqlSugar,国内团队制作,好用的很,但是.Net最低支持到4.5,而.Net45是不能在WinXP下运行,故可惜的放弃掉。   然后,找能在.Net40下运行的ORM,DosORM进入视野,但是发现有缺点,DosORM需要Model层都继承Entity类,而这个类在ORM.dll里,这样Model层将和ORM耦合,非常不好。而且DosTools工具生成的Model层,要求set里有onchange函数,而且还有内嵌类用于字段描述,简单的POCO,DosORM无法Update操作,造成Model层不干净。不佳。   转而,又延伸到Dapper,发现不错,1.52以下支持可以.Net40,对Model层简单set,get即可,无依赖,干净。缺点是它的CUDR需要写一些SQL,感觉不好,但是有个Dapper.SimpleCUDR的项目,引用后,可以支持简单泛型写法。那就选他了。其实在普通项目对DB层的需要,就是对单表的增删改查,多表的左连接查询,多表的事务更新,没有特别复杂的需求。   项目层次是,UI层引用Service层。Service层引用DB层。Model是独立的。DB层里包含Dapper和数据库连接器。Service层里有Dto

VS Code 添加移除asp.net core项目引用

跟風遠走 提交于 2020-04-24 06:53:12
原文: VS Code 添加移除asp.net core项目引用 VS Code 添加移除asp.net core项目引用 可以通过编辑.csproj文件来添加或者移除项目引用. 注意这里并没有智能提示, 最好是在Nuget网站(https://www.nuget.org/)搜索好相关包之后填写进来. 编辑结束之后, vscode会提示进行restore, 这就相当于在命令行执行dotnet restore命令. 此外, 也可以通过命令行来添加nuget包, 使用dotnet add package xxx命令来添加nuget包: 这时, csproj文件里就会出现AutoMapper的PackageReference: posted @ 2019-01-15 15:22 xtjatswc 阅读( ... ) 评论( ... ) 编辑 收藏 来源: oschina 链接: https://my.oschina.net/u/4387307/blog/3648956