automapper

How to simply map an NHibernate ISet to IList using AutoMapper

若如初见. 提交于 2019-12-18 03:48:12
问题 I'm trying to use AutoMapper to map from DTO's to my Domain. My DTO's might look like this: public class MyDTO { public string Name { get; set; } public bool OtherProperty { get; set; } public ChildDTO[] Children { get; set;} } public class ChildDTO { public string OtherName { get; set; } } My Domain objects like this: public class MyDomain { public string Name { get; set; } public bool OtherProperty { get; set; } public ISet<ChildDomain> Children { get; set; } } public class ChildDomain {

AutoMapper throwing StackOverflowException when calling ProjectTo<T>() on IQueryable

杀马特。学长 韩版系。学妹 提交于 2019-12-18 03:06:20
问题 I have created classes using EF Code First that have collections of each other. Entities: public class Field { public int Id { get; set; } public string Name { get; set; } public virtual List<AppUser> Teachers { get; set; } public Field() { Teachers = new List<AppUser>(); } } public class AppUser { public int Id { get; set; } public string Email { get; set; } public string Password { get; set; } public string UserName => Email; public virtual List<Field> Fields { get; set; } public AppUser()

Auto Mapper Unmapped members were found

最后都变了- 提交于 2019-12-18 01:19:17
问题 We are using Automapper for a project, and seem to get the following error randomly: AutoMapper.AutoMapperConfigurationException: Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type The code hasn't been changed in months. I get that error, refresh and the error is gone and page works fine. I'm using Mapper.AssertConfigurationIsValid(); not sure why it complains the mappings are

How to ignore all destination members, except the ones that are mapped? [duplicate]

六眼飞鱼酱① 提交于 2019-12-17 23:36:10
问题 This question already has answers here : AutoMapper: “Ignore the rest”? (16 answers) Closed 3 years ago . Is there a way to do this? We have a SummaryDto that maps from three different types, and when we create a map for each type, props that are not mapped are throwing an error. There are about 35 attributes on the summary dto. To use Ignore() option on each one is just too much trouble. Is there a global ignore? Something like CreateMap<Source,Target>() .IgnoreAllUnmapped(); 回答1: This is

Setting up Automapper 5.1

我是研究僧i 提交于 2019-12-17 22:59:45
问题 I am having trouble following the wiki in this instance. I wanted to use Automapper 5.2. I cannot find a simple end for end example that shows a solid configuration with context. By context I mean where do you put the config files and whats the difference between static and instance api? I checked out the DNRTV download but it deals with the 1.0 version. How do you set this package up? I have a model called Client as below. public class Client : IEntityBase { public Client() { Jobs = new List

Map a property to a collection item

左心房为你撑大大i 提交于 2019-12-17 22:47:11
问题 I've been sifting through AutoMapper documentation to try and find a recommended solution to this but haven't been able to find it. Let's say I have a class like the following public class Foo { public string Note { get; set; } } this class gets populated from the client and gets mapped to the following domain object class public class Bar { public IList<Note> Notes { get; set; } } where Note is public class Note { public string Text { get; set; } // other properties excluded for brevity } I

ASP.NET Core with EF Core - DTO Collection mapping

佐手、 提交于 2019-12-17 22:43:02
问题 I am trying to use (POST/PUT) a DTO object with a collection of child objects from JavaScript to an ASP.NET Core (Web API) with an EF Core context as my data source. The main DTO class is something like this ( simplified of course ): public class CustomerDto { public int Id { get;set } ... public IList<PersonDto> SomePersons { get; set; } ... } What I don't really know is how to map this to the Customer entity class in a way that does not include a lot of code just for finding out which

Automapper says Mapper.Map is obsolete, global mappings?

删除回忆录丶 提交于 2019-12-17 22:08:14
问题 I had defined in my project a global Automapper configuration that would allow me to use Mapper.Map<targetType>(sourceObject); in my code. (See my configuration below.) I updated the NuGet package, and I see the message that Mapper.Map is obsolete/depreciated. I went back to Automapper on GitHub and see examples like this: [Test] public void Example() { var config = new MapperConfiguration(cfg => { cfg.CreateMap<Source1, SubDest1>().FixRootDest(); cfg.CreateMap<Source2, SubDest2>()

Problems in creating unit test for ASP .NET MVC

做~自己de王妃 提交于 2019-12-17 21:09:28
问题 I am creating some unit tests for my ASP .NET MVC Controller class and I ran into some very strange errors: My controller code is below: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Delete(JournalViewModel journal) { var selectedJournal = Mapper.Map<JournalViewModel, Journal>(journal); var opStatus = _journalRepository.DeleteJournal(selectedJournal); if (!opStatus.Status) throw new System.Web.Http.HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); return

The method 'Where' cannot follow the method 'Select' or is not supported

China☆狼群 提交于 2019-12-17 21:07:32
问题 Why am I getting: The method 'Where' cannot follow the method 'Select' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods. ...when using the WHERE clause, like when calling: XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().Where(p => p.FirstName == "John").First(); ? This works: XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().First(); Also this works: