automapper

Help improving (refactoring) my code. Automapper - EF - asp.net mvc-3

北城以北 提交于 2019-12-23 04:51:57
问题 I have this 4 models - 2 Domain Models and 2 DTOs public class Project { public int ID { get; set; } public string Name { get; set; } public virtual ICollection<Task> Tasks { get; set; } } public class Task { public int ID { get; set; } public virtual int ProjectID { get; set; } public string Name { get; set; } public virtual Project Project { get; set; } } public class ProjectDTO { [Required] public string Name { get; set; } public List<TaskDTO> Tasks { get; set; } } public class TaskDTO {

Why do I get exception for AutoMapper int to int[] array

一个人想着一个人 提交于 2019-12-23 03:26:33
问题 I'm using the AutoMapper object mapper, but am getting the exception "Custom configuration for members is only supported for top-level individual members on a type." Basically I have public class Obj1 { public int Id {get;set;} } and public class Obj2 { public int[] Ids { get; set; } } Th exception occurs when I try to create the mapping like; Mapper .CreateMap<Obj1, Obj2>() .ForMember(d => d.Ids[0], o => o.MapFrom(s => s.Id) ); Why is this happening ? What I'm wanting to achieve is when the

Updating a many-to-many relationship

£可爱£侵袭症+ 提交于 2019-12-23 03:04:58
问题 I've asked the question a few different times in a few different ways and I haven't yet gotten any responses. I'm trying again because I feel like my solution is too convoluted and I must be missing something simpler to do. Using EF 4.1, POCO, DbContext API, AutoMapper, and Razor in an MVC 3 application. I have a many-to-many relationship between two of my entities: Proposals and CategoryTags. I can successfully map (Automapper) a Proposal to my ProposalViewModel including the collection of

Missing type map configuration or unsupported mapping

坚强是说给别人听的谎言 提交于 2019-12-23 02:54:23
问题 Could somebody please explain what this error means? I have used automapper onces before but never had this kind of error. Error The server encountered an error processing the request. The exception message is 'Missing type map configuration or unsupported mapping. Mapping types: Char -> QuestionDto System.Char -> CollectiveDistributedPolling.QuestionDto Destination path: QuestionDto.Question1.Question1.Question10[0] Source value: R'. Service1.svc.cs public Service1() { Mapper.CreateMap

AutoMapper a viable alternative to two way databinding using a FormView?

余生长醉 提交于 2019-12-23 01:59:08
问题 I've started using the FormView control to enable two way databinding in asp.net webforms. I liked that it saved me the trouble of writing loadForm and unloadForm routines on every page. So it seemed to work nicely at the start when I was just using textboxes everywhere....but when it came time to start converting some to DropDownLists, all hell broke lose. For example, see: Not possible to load DropDownList on FormView from code behind? ....and I had many additional problems after that. So I

How to recursively map entity to view model with Automapper function call?

*爱你&永不变心* 提交于 2019-12-23 01:41:27
问题 Spin off of my earlier question -> How to map .NET function call to property automatically? I have some related entity objects that I want to map to view models, and each mapping to a view model needs to call a function for the mapping. The tricky part is that the entity function returns another entity which needs to be mapped to it's view model. The flow is somewhat like this. CartEntity > CartViewModel > CartEntity.GetCartItems() > CartViewModel.CartItems > CartEntity.GetCartItems().GetItem

How to recursively map entity to view model with Automapper function call?

为君一笑 提交于 2019-12-23 01:41:19
问题 Spin off of my earlier question -> How to map .NET function call to property automatically? I have some related entity objects that I want to map to view models, and each mapping to a view model needs to call a function for the mapping. The tricky part is that the entity function returns another entity which needs to be mapped to it's view model. The flow is somewhat like this. CartEntity > CartViewModel > CartEntity.GetCartItems() > CartViewModel.CartItems > CartEntity.GetCartItems().GetItem

AutoMapper with a list data from IDataReader

风格不统一 提交于 2019-12-22 17:54:15
问题 using (IDataReader dr = DatabaseContext.ExecuteReader(command)) { if (dr.Read()) { AutoMapper.Mapper.CreateMap<IDataReader, ProductModel>(); return AutoMapper.Mapper.Map<IDataReader, IList<ProductModel>>(dr); } return null; } if dr has only one row -> error: threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' if dr has more than one row, it run ok . any help? 回答1: The problem is that Automapper is calling Read() as well - so is trying to always look at the

AutoMapping custom Generic Types - How?

吃可爱长大的小学妹 提交于 2019-12-22 12:46:05
问题 hey guys, I'm using automapper version 1.1.0.188 In my AutoMapper.Configure I'm mapping Entities to DTOs and vice versa, like so: // entity >> DTO Mapper.CreateMap<MetaTemplate, MetaTemplateDTO>(); Mapper.CreateMap<Person, PersonDTO>(); // DTO >> Entity Mapper.CreateMap<MetaTemplateDTO, MetaTemplate>(); Mapper.CreateMap<PersonDTO, Person>(); When I do the below mappings (and vice versa) everything works fine Mapper.Map<entity, entityDTO>(entity); Mapper.Map<List<entity>, List<entityDTO>>

When migrating to AutoMapper 4.2/5.0, should I store an IMapper instance or the MapperConfiguration instance in my dependency injection container?

情到浓时终转凉″ 提交于 2019-12-22 12:40:47
问题 I am migrating to the newer configuration of AutoMapper. I was looking at examples on the AutoMapper GitHub Wiki and am a little confused on how to complete the configuration. The Wiki says in one place you can store the MapperConfiguration instance in your D.I. container (or store it statically), but the next paragraph says you can store the Mapper instance statically. In a nutshell, I am not sure if I should be doing var config = new MapperConfiguration(cfg => { cfg.CreateMap<Foo, Bar>()