I want to map my Entity Framework entities (generated from a legacy database) to custom DTO objects (which should be nice and clean). My legacy DB has entities looking a bit like this: internal class Order { int id; string Shipping_date; string quantity; } And I want to map it to a nicer DTO object: public class OrderDto { int id; DateTime? ShippingDate; int Quantity;
我想映射我的实体框架实体(从遗留数据库生成)到自定义的DTO对象(应该很好,干净)。 我的遗留数据库的实体看起来有点像这样: internal class Order { int id; string Shipping_date; string quantity; } 我想将它映射到更好的DTO对象: public class OrderDto { int id; DateTime? ShippingDate; int Quantity; } 我写了一个“实体容器”来提供依赖注入,它以这种方式返回值: public IEnumerab
Please can any one advise how to use conditional mapping in AutoMapper to map a value in the TARGET object from a SOURCE object based upon an existing TARGET property value? So my source class is: public class UserDetails { public String Nickname { get; set; } } My target class is: public class ProfileViewModel { public Boolean NicknameIsVisible { get; set; public String Nickname
请任何人建议如何使用AutoMapper中的条件映射根据现有的TARGET属性值从SOURCE对象映射TARGET对象中的值? 所以我的源类是: public class UserDetails { public String Nickname { get; set; } } 我的目标课程是: public class ProfileViewModel { public Boolean NicknameIsVisible { get; set; public String Nickname { get; set; } } 我只想在目标属性“NicknameIsVisible”值已设置为TRUE的情况下,在目标
I am trying to map my DTO object to entity object in my factory class. DTO has all field values straight, whereas entity has fields which consist of Name and Value. After some debugging, I found Automapper instantiates each entity fields instead of using existing one. As a result, the last test fails. [TestFixture] class RecursiveMappingTest { public class SourceInfo { public
我试图将我的DTO对象映射到工厂类中的实体对象。 DTO具有所有字段值,而实体具有由名称和值组成的字段。 经过一些调试后,我发现Automapper实例化每个实体字段,而不是使用现有字段。 结果,最后一次测试失败。 [TestFixture] class RecursiveMappingTest { public class SourceInfo { public string Info1 = "info1"; public string Info2 = "info1"; } public class StringField {
I'm updating our automapper libraries from version 3 to version 5.2.0 and I'm getting this error System.InvalidOperationException: System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'System.Int32' on this line of code in the mapping setup for two complex objects. cfg.CreateMap<objA, objB>() .ForAllMembers(config => config.NullSu
我正在将我们的automapper库从版本3更新到版本5.2.0,并且出现此错误 System.InvalidOperationException: System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'System.Int32' 在两个复杂对象的映射设置中的这一行代码中。 cfg.CreateMap<objA, objB>() .ForAllMembers(config => config.NullSubstitute(string.Empty)); 我猜这发生了,因为它不能将int设置为nu
I have a View Model such as public class RootViewModel { public CreateCompanyViewModel Company { get; set; } public string Name { get; set; } public string Email { get; set; } public string PhoneNumber { get; set; } public string Password { get; set; } public string ConfirmPassword { get; set; } public CreateUserTypeViewModel UserType { get; set; } } And Create
我有一个视图模型,如 public class RootViewModel { public CreateCompanyViewModel Company { get; set; } public string Name { get; set; } public string Email { get; set; } public string PhoneNumber { get; set; } public string Password { get; set; } public string ConfirmPassword { get; set; } public CreateUserTypeViewModel UserType { get; set; } } 而CreateCompanyV
Using AutoMapper, I'm trying to map two types that I pull from two different assemblies via reflection. However, when working with Types, I am unable to get the .ForMember() method to ignore any members that I specify. The regular lambda syntax does not compile because the member name is not found on the Type type of the class. Passing in a string of the member allows compilation, but stil
使用AutoMapper,我试图映射两种类型,我通过反射从两个不同的组件中抽取出来。 但是,使用类型时,我无法使.ForMember()方法忽略我指定的任何成员。 常规的lambda语法不会编译,因为在类的Type类型上找不到成员名称。 传递成员的字符串允许编译,但仍不会忽略成员。 使用config.AssertConfigurationIsValid()表明这是一个无效的配置。 class ExampleSchema { public int Age {get; set;} } class ExampleDto {
I have an object graph that I'm loading from a database using EF CodeFirst and AutoMapper into DTOs:- public class Foo { public int Id { get; set; } public virtual ICollection<Bar> Bars { get; set; } } public class Bar { public int Id { get; set; } public int FooId { get; set; } public virtual Foo Foo { get; set; } public string Name { get; set; } public int SortOrder {
我有一个使用EF CodeFirst和AutoMapper从数据库加载到DTO的对象图: - public class Foo { public int Id { get; set; } public virtual ICollection<Bar> Bars { get; set; } } public class Bar { public int Id { get; set; } public int FooId { get; set; } public virtual Foo Foo { get; set; } public string Name { get; set; } public int SortOrder { get; set; } } public class FooDto {
I am trying to configure AutoMapper to work with a class which requires a constructor argument. I've done quite a bit of online research into this, and found several examples...but they either don't use instance-based AutoMapper, or they are for older versions of AutoMapper. I'm using AutoMapper to deep clone objects. Here's the profile I've created: public class ScannerA
我正在尝试将AutoMapper配置为需要构造函数参数的类。 我已经完成了很多关于这方面的在线研究,并发现了几个例子......但他们要么不使用基于实例的AutoMapper,要么他们使用旧版本的AutoMapper。 我使用AutoMapper深入克隆对象。 这是我创建的配置文件: public class ScannerAutoMapProfile : Profile { public ScannerAutoMapProfile() { CreateMap<AzureConfiguration>(); CreateMap<Co
EDIT: to include TypeConverter To set the stage, I am stripping out code from a existing WCF service to put into a business object (BO) that will be referenced by the WCF to provide clients with information. A requirement is to make the employeeId of an Employee object to be an integer rather than the string currently used. I'm using AutoMapper to map all of the objects between the BO and
编辑:包括TypeConverter 为了设置阶段,我从现有的WCF服务中剥离代码,放入一个业务对象(BO)中,该对象将被WCF引用以向客户端提供信息。 要求是将Employee对象的employeeId设置为一个整数而不是当前使用的字符串。 我使用AutoMapper来映射BO和WCF之间的所有对象,以便合约不会中断。 然而,我正在努力如何为EmployeeId来回映射为BO中的整数,并仍然通过WCF以合约方式提供字符串。 BO public class Employee { pub
I want AutoMapper to map automatically Members like this: class Model { public int ModelId { get; set; } } class ModelDto { public int Id { get; set; } } Here, I would do a CreateMap<Model, ModelDTO>() .ForMember(x => x.Id, e => e.MapFrom(x => x.ModelId) But, how could I make AutoMapper do the mapping automatically? Most of my classes are like that. The Primary ke
我想让AutoMapper自动映射这样的成员: class Model {public int ModelId {get; 组; }} class ModelDto {public int Id {get; 组; }} 在这里,我会做一个 CreateMap<Model, ModelDTO>() .ForMember(x => x.Id, e => e.MapFrom(x => x.ModelId) 但是,我怎么能让AutoMapper自动执行映射? 我的大部分课程都是这样的。 主键的形式为:ClassName +“Id”。 编辑: 我试过这个,但它不起作用: c