草庐IT

automapper-2

全部标签

c# - 可以使用 AutoMapper 将一个对象映射到对象列表吗?

这些是我的类(class):publicclassEventLog{publicstringSystemId{get;set;}publicstringUserId{get;set;}publicListEvents{get;set;}}publicclassEvent{publicstringEventId{get;set;}publicstringMessage{get;set;}}publicclassEventDTO{publicstringSystemId{get;set;}publicstringUserId{get;set;}publicstringEventId{get

c# - AutoMapper 使用错误的构造函数

今天,我使用AutoMapperv1.1升级了一个功能齐全的应用程序,现在使用AutoMapperv2.1,我遇到了一些使用以前的版本从未遇到过的问题。这是我的代码从Dto映射回Domain对象的示例publicclassTypeOne{publicTypeOne(){}publicTypeOne(TypeTwotwo){//throwexiftwoisnull}publicTypeOne(TypeTwotwo,TypeThreethree){//throwexiftwoorthreearenull}publicTypeTwoTwo{get;privateset;}publicType

c# - 需要加速automapper ...做113个对象需要32秒

您好,我在使用自动映射器时遇到了一些重大问题,而且速度很慢。我不确定如何加快速度。我正在使用nhibernate、fluentnhibernate和asp.netmvc3.0[Serializable()]publicclassTest{publicvirtualintId{get;privateset;}publicvirtualstringName{get;set;}publicvirtualstringDescription{get;set;}publicvirtualDateTimeDate{get;set;}publicvirtualIListReminders{get;se

c# - 如何在 Automapper 6 映射期间忽略所有源成员的空值?

我到处都在寻找:stackoverflow、automapper文档、互联网,只是找不到关于这个的任何信息,即使这似乎是一个非常普遍的问题。我的映射:CreateMap().ForAllMembers(opt=>opt.Condition(src=>src!=null));这不起作用,因为src代表源对象(StatusLevelDTO),而不是源属性(我认为)。更具体地说,如果我将ObjectA映射到ObjectB,ObjectA.SomeValue为null而ObjectB.SomeValue为2,我希望目标对象保留其值(2)。我看过这个问题:Automapperskipnullva

c# - AutoMapper 映射如果不为空,否则自定义转换

这是我的代码:Mapper.CreateMap().ForMember(dest=>dest.Bar,opt=>opt.MapFrom(src=>src.Bar==null?newBarViewModel():src.Bar))基本上,“BarViewModel”有一个无参数的构造函数,它在类中设置属性。所以我想对AutoMapper说:Ifthevalueisnull,thenusethectorfortheclass.otherwiseusethemappingyouhaveinplace以上是给我一个C#编译器错误。我猜类型转换也行不通。那么有没有AutoMapper技巧可以做到

c# - 使用 AutoMapper 映射集合

我正在尝试将数组映射到ICollection类型.基本上我希望能够做到:Mapper.CreateMap();在哪里Y是Collection有什么想法吗? 最佳答案 您不需要为集合设置映射,只需设置元素类型。所以只是:Mapper.CreateMap();Mapper.Map>(objectToMap);查看此处了解更多信息:http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home

c# - 在 Automapper 中使用 Profiles 来映射具有不同逻辑的相同类型

我在我的ASP.NETMVC网站中使用AutoMapper将我的数据库对象映射到ViewModel对象,我正在尝试使用多个配置文件来映射相同的类型,但使用的是另一种逻辑。我是通过阅读Matt'sblogpost想到这样做的他说:ThereallykeypartistheAutoMapperconfigurationprofile.Youcangroupconfigurationswithprofiles.Maybeinoneprofileyouformatdatesinoneway,inanotherprofileyouformatdatesinanotherway.I’mjustus

c# - 如何在 AutoMapper 中配置条件映射?

假设我有以下实体(类)publicclassTarget{publicstringValue;}publicclassSource{publicstringValue1;publicstringValue2;}现在我想配置自动映射,如果Value1以“A”开头,则将Value1映射到Value,否则我想将Value2映射到Value。这是我目前所拥有的:Mapper.CreateMap().ForMember(t=>t.Value,o=>{o.Condition(s=>s.Value1.StartsWith("A"));o.MapFrom(s=>s.Value1);>})然而,我仍然无

c# - 如何通过 AutoMapper 将匿名对象映射到类?

我有一个实体:publicclassTag{publicintId{get;set;}publicstringWord{get;set;}//otherproperties...//andacollectionofblogposts:publicICollectionPosts{get;set;}}和一个模型:publicclassTagModel{publicintId{get;set;}publicstringWord{get;set;}//otherproperties...//andacollectionofblogposts:publicintPostsCount{get;s

c# - AutoMapper 和继承 - 如何映射?

有这个场景:publicclassBase{publicstringName;}publicClassClassA:Base{publicint32Number;}publicClassClassB:Base{publicstringDescription;}publicClassDTO{publicstringName;publicint32Number;publicstringDescription;}我有一个IList我的map是:AutoMapper.Mapper.CreateMap,IList>().ForMember(dest=>dest.Number,opt=>opt.I