问题标签 [automapper-6]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
asp.net-core - Automapper 和 EF 导航属性
使用 ASP.NET MVC Core 和 Entity Framework Core,我正在尝试创建一个简单的网站。
我已经定义了我的模型:
以及相应的视图模型:
我已经使用相应的映射器定义了一个 Automapper 配置文件:
我尝试加载一个Club
实体,其中包含导航属性Teams
( _context.Club.Include(c => c.Teams).ToList()
)。这按预期工作,它返回一个带有团队列表的俱乐部。但是当我尝试将此实例映射到 ClubViewModel 时,我收到502.3 错误,并且我的调试会话立即结束。
好像我错过了一些微不足道的东西,但我根本看不到它。Windows 事件日志中没有任何信息,我在 IIS Express 日志记录中找不到任何有用的信息 (%userprofile%\documents\IISExpress)
是什么导致了崩溃?
c# - AutoMapper not calling AfterMap when mapping a dynamic proxy
Let's say I've designed a class A
and also I've designed a DTO class called Dto
.
If A
is a dynamic proxy generated with Castle DynamicProxy, AutoMapper won't fire AfterMap
:
In the other hand, if I run the following code, AfterMap
will be called:
Also, MappingConfiguration
is configured to automatically register types:
Currently I'm using AutoMapper 6.0.2. I can't figure out why this isn't working.
Update
After some trial-errors, It started to work once I commented out config.CreateMisstingTypeMaps
or I set it to false
.
I suspect that AutoMapper is creating a map between the DTO and AProxy
(which is a type generated during run-time) and prioritizes that mapping over the Dto
and A
as is.
Thus, how may I configure AutoMapper to both create missing type maps and also support my scenario?