问题标签 [automapper-3]

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.

0 投票
0 回答
99 浏览

automapper - Restore < AutoMapper 3.1 null -> empty array behaviour

With AutoMapper <= 3.0, this following test passes.

As of version 3.1, the should_map_array_to_empty assertion fails because destination.Data is set to null and not an empty array as previously. Is there a way to restore the previous behaviour, preferably globally as opposed to individually per configured map?

The configuration option Mapper.Configuration.AllowNullCollections = false appears to make no difference in this case regardless of the versions of AutoMapper I've tried.

0 投票
1 回答
639 浏览

c# - 使用 --aot-only 运行时调用 Automapper 时引发 Xamarin.iOS 异常



在使用 Xamarin 进行调试期间,我无法让 AutoMapper (3.2.1.0) 在 iPad 上工作。我已经使用 Xamarin studio 3 和 Xamarin.iOS 7.2.3.39 将 mac 设置为构建主机。在我的 Windows 系统上,我使用 Visual Studio 2012。

在我的解决方案中,我有两个项目:
- PortableClassLibrary
- MySampleApplication

在 PortableClassLibrary 项目中,我有以下代码:

运行调试器时出现以下异常:

我确实尝试使用
..\packages\AutoMapper.3.2.1\lib\portable-windows8+net40+wp8+wpa81+sl5+MonoAndroid+MonoTouch\AutoMapper.dll

..\packages\AutoMapper.3.2.1\lib \portable-windows8+net40+wp8+sl5+MonoAndroid+MonoTouch \AutoMapper.dll

但这对于异常没有区别。

我看起来 Automapper 正在尝试使用值类型创建字典,但这是给定 url 中描述的限制之一。

有什么我想念的东西让这个工作吗?

干杯,

安德烈

0 投票
0 回答
1570 浏览

automapper - 同一类型的多个映射(不同的规则)

我正在使用Automapper将我的域模型(nHibernate)映射到我的视图模型并返回。一切都很顺利。

现在我需要将一个实体(域实体)映射到自身,因为我想在那里定义一些业务规则。

我需要多次为同一类型定义不同的映射。我已经为每种类型的映射使用了配置文件:

这是我的个人资料(简化):

如您所见,我需要在AfterMap中做一些事情。

我的第二个配置文件OrderToOrder2MapperProfile看起来与此处显示的相似,因此我不会粘贴代码。

当我映射我的对象时:

两个配置文件都被处理。

我决定遵循SO 上建议的路径,并创建了我的“自定义”引擎:

现在一切正常,除了线的映射;即使我使用自定义引擎来映射我的对象,两个管道也会被处理:

我想问题在于我在这里使用单例映射器(引擎):

我试图找到一种在分析器中使用当前引擎的方法,但我似乎无法以任何方式获得它。

唯一可能的解决方案是在我的探查器的构造函数中传递引擎:

并在此处使用当前引擎:

问题:

这是唯一可能的解决方案还是有更好的选择?
我做事的方式正确吗?

如果有人感兴趣,我已经创建了一个使用StructureMap作为测试用例的github 存储库。

0 投票
1 回答
15602 浏览

c# - Automapper IEnumerable到 IEnumerable无需创建地图配置

我无法使以下工作,其中数组是 CustomerContract 的数组:

在我看来,第一个例子应该足够了,但我无法工作。我已经阅读了 automapper 的配置维基(https://github.com/AutoMapper/AutoMapper/wiki/Configuration),但我不明白为什么这应该是必要的。Automapper 需要的一切都在命令中定义。它是哪种类型(对象和列表),以及我希望它映射到哪个对象。

我只是不了解 Automapper 的核心概念吗?

我的例外听起来像这样:

缺少类型映射配置或不支持的映射。
映射类型:\r\nCustomerContract -> Customer\r\nStimline.Xplorer.Repository.CustomerService.CustomerContract -> Stimline.Xplorer.BusinessObjects.Customer
目标路径:List`1[0]
源值:Stimline.Xplorer.Repository.CustomerService .客户合同

0 投票
2 回答
1524 浏览

iqueryable - 将 IEnumerable 转换为 IQueryable 以使用 Automapper Extension Project()

我们在应用程序中大量使用存储过程,并使用 LinqToSql 执行我们的过程并填充要从 DB 访问方法返回的 List 对象。但是,我们需要使用 AutoMapper 和显然 AutoMapper 扩展 Project() 将一些对象映射到另一种对象类型。To 需要 IQuryable 而 List 是实现 IEnumerable。

源代码:

编译错误:

System.Collections.Generic.List' 不包含“Project”的定义,并且找不到接受“System.Collections.Generic.List”类型的第一个参数的扩展方法“Project”(您是否缺少 using 指令或程序集参考?)文件夹\Common\MasterDataRepository.cs 116 28 Omnicx.Data

0 投票
1 回答
603 浏览

c# - Automapper options.ignore() 不适用于列表

.ForMember(c = c.Property, options => options.Ignore())当您使用单个对象进行映射时有效。但是,忽略在列表的情况下不起作用。例如,请参见下面的代码,其中目标列表对象已经有一些条目,并且在映射时,我想根据创建的映射忽略特定属性。当映射发生时,忽略规则不适用,值仅从源设置

//现在在 destCust 实例中,我希望 Next 基于 options.ignore 属性 Next.. 保留值“Hrishi”,但它不会发生。此值设置为空。

0 投票
1 回答
835 浏览

c# - Inconsistent Mapping Behavior in AutoMapper 3

I've had issues with AutoMapper 3 mapping related entities from entity framework to a view model some of the time in MVC 5. I'm using EF 6.1.1 to get the data, and a thin and light repository layer to centralize queries. That issue only seems to occur with mapping properties from entities under a root entity, but the problem is intermittent. I've seen the behavior start working again after rebuilding the solution and the behavior break after rebuilding the solution without changing the code where the issue occurs.

I've tested this in the debugger and SQL profiler, and even when the data isn't showing up on the front end, I can see in the SQL profiler that Entity Framework is loading the related tables.

Example mapping with the issue

This code executes in the MVC controller after the data has been queried from the repository layer. The view model will then be passed off to the view for rendering.

Another example mapping with the issue

Same basic execution path under a different controller action, same problem.

Again, sometimes the three properties get data, and sometimes they don't.

Data Model

This is what the Data Model looks like.

The part of the edmx file with the data model for this question

Repository

The repository layers wraps up the entity framework calls, but it does not abstract away the entity framework entities and the issues and benefits it has. All repositories in the project inherit IRepository, and I'm using this layer to centralize query and business logic.

Summary

I don't believe this is an Entity Framework lazy loading issue, and after forcing EF to eager load the data, the problem persists. The entities have the values in the debugger before mapping, but only sometimes will the value get mapped to the view model. The most frustrating thing is that the issue does not seem to be caused by any changes I've made to the view model.

What can cause such inconsistent behavior? I've had this problem with both AutoMapper 3.2.1 and 3.1.1.

0 投票
2 回答
21144 浏览

entity-framework-6 - Automapper 导致错误:缺少类型映射配置或不支持的映射

我是 Automapper 的新手。

我已将 Nuget 包 - Automapper 添加到我的管理器 (BLL) 和 DAL 层中。

现在,下面是相关的东西:

以下是经理库的声明,它给了我例外:

例外情况如下:

缺少类型映射配置或不支持的映射。

映射类型:
studentDTO ->
StudentMaster Admin.App.DTO.studentDTO-> Admin.App.DAL.StudentMaster

如果在 EF 上进行 select/where 查询,它正在工作并且能够使用映射

我写了一个Autoconfiguration.cs文件如下:

笔记:

实体- StudentMaster(模型)实体StudentDTO都具有相同的属性。

请指导我如何解决这个问题。

谢谢你

0 投票
1 回答
431 浏览

automapper - 如何使用 AutoMapper 将三个或 N 个复杂对象映射到一个对象

我是 AutoMapper 框架的新手。我有三到五个必须映射到一个对象的复杂对象

例如,必须将 ChipInfo、HardDiskInfo、MonitorInfo、MemoryCardInfo 映射到 LaptopInfo,因为 LaptopInfo 对象具有必须从所有四个对象中填充的字段。

如何使用 AutoMapper 实现这一点。我找不到任何允许我使用 .ForMember 对四个对象执行 CreateMap 的答案。请帮忙谢谢

以下是更新的代码

0 投票
1 回答
214 浏览

.net - 使用 Xamarin Studio 时 AutoMapper NuGet 未构建

我有一个由 VS2013 创建并托管在 GitHub 上的解决方案,它可以构建。我试图在 Xamarin Studio 上构建它,但它给了我这个错误

构建目标 CopyAutoMapperAssembly 时出错:无法解析条件“$([System.String]::new('%(ReferencePath.Filename)').StartsWith('AutoMapper.'))”:标点符号无效:[

我禁用了从项目文件中删除选项的 NuGet 包还原功能,但它并没有解决问题。

如果想在 Xamarin Studio 上尝试该项目,这是该项目:https ://github.com/Ar3sDevelopment/Caelan.Frameworks.BIZ/tree/dev (只有 dev 分支有修复)