jjzjj

Automapper

全部标签

c# - 我怎么知道 automapper 是否已经初始化?

有没有办法知道automapper是否已经初始化?例如:AutoMapper.Mapper.IsInitialized();//wouldreturnfalseAutoMapper.Mapper.Initialize(/*optionshere*/);AutoMapper.Mapper.IsInitialized();//wouldreturntrue谢谢! 最佳答案 您可以在初始化映射器之前调用Mapper.Reset();。我在初始化我的单元测试类时这样做:[ClassInitialize]publicstaticvoidCla

c# - AutoMapper 无法将 TestDbAsyncEnumerable 转换为 IQueryable

我已经实现了来自https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113).aspx的TestDbAsync伪造并且我希望能够在调用AsyncEF方法(ToListAsync、CountAsync等)之前使用AutoMapper投影到不同的类型。我在ProjectionExpression.To中得到一个转换异常抛出异常的示例代码。_userRepository.GetAll().OrderBy(x=>x.Id).ProjectTo.ToListAsync();这在非测试场景中工作正常,但是当我使用TestDbAsyncEnu

c# - 如何自动映射这个(映射子成员)

我有这样的东西publicclassProductViewModel{publicintSelectedProductId{get;set;}publicstringProductName{get;set;}publicintQty{get;set;}publicListProducts{get;set};}我有一个这样的域名publicclassProduct{publicintProductId{get;set;}publicstringProductName{get;set;}publicintQty{get;set;}}publicclassStore{publicProduc

c# - 如何使用 AutoMapper 将目标对象映射到源对象中的子对象?

我有这样的源对象和目标对象:classProductWithCategories//Sourceclass{publicProductProduct{get;set;}//ProductisanEFentityclasspublicIEnumerableCategories{get;set;}}classProductViewModel//Destclass{publicintId{get;set;}//OtherpropertieswiththesamenameasProductclasspublicIEnumerableCategories{get;set;}}因此,我需要将sou

c# - .net 中的对象复制方法 : Auto Mapper, Emit Mapper、隐式操作、属性复制

如果有人知道在.NET中执行此操作的更多方法,您对这些方法有何看法?您选择哪种方法,为什么?下面是.NET中对象拷贝不同方式的测试。与此原始线程相关的测试:HowtocopyvaluefromclassXtoclassYwiththesamepropertynameinc#?所以,在这里,您可以自己运行它:staticvoidMain(string[]args){Student_student=newStudent();_student.Id=1;_student.Name="Timmmmmmmmaaaahhhh";_student.Courses=newList();_student

c# - 使用 AutoMapper 自定义映射

我有两个非常简单的对象:publicclassCategoryDto{publicstringId{get;set;}publicstringMyValueProperty{get;set;}}publicclassCategory{publicstringId{get;set;}[MapTo("MyValueProperty")]publicstringKey{get;set;}}当使用AutoMapper将Category映射到CategoryDto时,我想要以下行为:除了具有MapTo属性的属性外,属性应该照常映射。在这种情况下,我必须读取Attribute的值才能找到目标属性。

c# - 双向映射有什么问题?

我已经成功使用AutoMapper几个月了,但现在我遇到了一些绊脚石。我需要(或认为我需要)的是2向映射。这是当我从数据库加载一个项目在屏幕上播放时(域对象->View模型)以及当用户对所述项目进行更改并将其映射回我的域对象(View模型->域对象)时。我知道我可以简单地在我的配置文件中创建一个映射来处理双向映射,但我正在阅读here双向映射是不必要的。许多人表示,这样做是对没有解决更大问题(无论可能是什么)的回应。我只是想知道为什么这是一种代码味道? 最佳答案 当我还是一名初级开发人员时,我参与了一个大型项目,该项目基本上实现了您

c# - 如何使用 AutoMapper 将多个子类映射到一个类中?

假设我有三个类,它们是基类的子类:publicclassBaseClass{publicstringBaseName{get;set;}}publicclassSubclass1:BaseClass{publicstringSubName1{get;set;}}publicclassSubclass2:BaseClass{publicstringSubName2{get;set;}}publicclassSubclass3:BaseClass{publicstringSubName3{get;set;}}我想将它们映射到如下所示的ViewModel类:publicclassViewMo

c# - AutoMapper——继承映射不​​工作,相同的源,多个目的地

我可以在AutoMapper(v2.2)中对源类型相同但目标类型不同的映射使用继承映射吗?我有这样的基本情况(真正的类有更多的属性):publicabstractclassBaseViewModel{publicintCommonProperty{get;set;}}publicclassViewModelA:BaseViewModel{publicintPropertyA{get;set;}}publicclassViewModelB:BaseViewModel{publicintPropertyB{get;set;}}ViewModelA和ViewModelB是同一实体类的不同表示

c# - 如何将 AutoMapper 与 Ninject.Web.Mvc 一起使用?

设置我有一个AutoMapperConfiguration设置AutoMapper映射的静态类:staticclassAutoMapperConfiguration(){internalstaticvoidSetupMappings(){Mapper.CreateMap.ConvertUsing>();}}哪里IdToEntityConverter是定制ITypeConverter看起来像这样:classIdToEntityConverter:ITypeConverterwhereT:Entity{privatereadonlyIRepository_repo;publicIdToEn