automapper

Autofac 3 and Automapper

断了今生、忘了曾经 提交于 2019-12-05 02:03:37
问题 Does anyone know of a comprehensive guide to setting up Automapper with Autofac. I'm new to both but I have played around with the static Mapper class however I want to be able to mock and inject IMappingEngine and create a configuration that sets up all my mappings. All the guides I have looked at so far don't really explain what is going on and I can't quite work it out. Also I am using Autofac 3.0 which seems to have some differences in the ContainerBuilder methods which doesn't help (the

C# AutoMapper Conditional Mapping based upon target value

不羁的心 提交于 2019-12-05 01:42:33
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 { get; set; } } I want to set the "Nickname" property value in the TARGET to match the "Nickname" property value in the SOURCE only if the target property "NicknameIsVisible" value is already set to TRUE, otherwise I

AutoMapper - How to pass parameters into a Custom Resolver using ConstructedBy method?

有些话、适合烂在心里 提交于 2019-12-05 00:31:38
问题 In my ASP.NET MVC 2 (RC) project - I'm using AutoMapper to map between a Linq to Sql class (Media) and a view model (MediaVM). The view model has a SelectList property for a drop down in the view. I have a custom value resolver to populate the SelectList property items from the db, but am wondering if there's a way to pass a couple values from the source model into the resolver (using ConstructedBy method?) to a) define the selected item and b) filter the items from the db. The source object

Many-to-many to DTOs using Automapper

廉价感情. 提交于 2019-12-05 00:01:03
问题 If I have a many-to-many relationship defined in EF: public class StudentImage { public int StudentId { get; set; } public int ImageId { get; set; } public int Order { get; set; } public virtual Student Student { get; set; } public virtual Image Image { get; set; } } public class Student { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<StudentImage> Images { get; set; } } public class Image { public int Id { get; set; } public string Filename { get;

Automapper ResolveUsing cause “Can't resolve this to Queryable Expression”

陌路散爱 提交于 2019-12-04 23:50:16
I'm using autommaper to map domain classes to model classes and viceversa. I need to encrypt/decrypt one property. When I map Model to Domain there isn't problem, work perefectly: Mapper.CreateMap<EntityModel, Entity>().ForMember(dest => dest.Password, opt => opt.ResolveUsing(src => this.EncryptString(src.Password))) But when map Entity to Model automapper crash and throws "Can't resolve this to Queryable Expression": Mapper.CreateMap<Entity, EntityModel>().ForMember(dest => dest.Password, opt => opt.ResolveUsing(src => this.DecryptString(src.Password))) I've tried with a Custom Value Resolver

AutoMapper flattening of nested mappings asks for a custom resolver

有些话、适合烂在心里 提交于 2019-12-04 23:42:28
I'm somewhat new to AutoMapper and wanted to map a POCO-ish object to a perhaps more complex DTO, the latter tries to be a representation of a Google Books API's Volume resource: Book.cs public class Book { public string Isbn10 { get; set; } public string Isbn13 { get; set; } public string Title { get; set; } public string Author { get; set; } public string Publisher { get; set; } public DateTime Publication { get; set; } public int Pages { get; set; } public string Description { get; set; } public bool InStock { get; set; } } BookDto.cs public class BookDto { public string Kind { get; set; }

AutoMapper: Why is UseValue only executed once

…衆ロ難τιáo~ 提交于 2019-12-04 23:15:33
Why is UseValue only executed once? I need to call the TeamRepository for each request. How can I achieve this? Mapping from TeamEmployee to TeamEmployeeInput: CreateMap<TeamEmployee, TeamEmployeeInput>() .ForMember(x => x.Teams, x => x.UseValue(GetTeamEmployeeInputs())) .ForMember(d => d.SelectedTeam, s => s.MapFrom(x => x.Team == null ? 0 : x.Team.Id)); private IEnumerable<TeamDropDownInput> GetTeamEmployeeInputs() { Team[] teams = CreateDependency<ITeamRepository>().GetAll(); return Mapper.Map<Team[], TeamDropDownInput[]>(teams); } Domain object: public class TeamEmployee : Entity { public

Automapper + EF4 + ASP.NET MVC - getting 'context disposed' error (I know why, but how to fix it?)

佐手、 提交于 2019-12-04 23:14:39
问题 I have this really basic code in a MVC controller action. It maps an Operation model class to a very basic OperationVM view-model class . public class OperationVM: Operation { public CategoryVM CategoryVM { get; set; } } I need to load the complete list of categories in order to create a CategoryVM instance. Here's how I (try to) create a List<OperationVM> to show in the view. public class OperationsController : Controller { private SomeContext context = new SomeContext (); public ViewResult

Using automapper to apply a filter to a collection

徘徊边缘 提交于 2019-12-04 22:43:38
I have a domain model that contains a collection and I want to use AutoMapper to map the parent and children to the view model but I don't want children that have been "soft" deleted to be taken across. For instance: public class Customer { public EntitySet<Order> {get;set;} } public class Order { public DateTime? DeletedDate {get;set;} } my AutoMapper definition would be Mapper.CreateMap<Customer, CustomerViewModel>(); Mapper.CreateMap<Order, OrderViewModel>(); and I don't want Orders to be in the view model that have a value for DeletedDate. Is that possible in AutoMapper? Many thanks in

Is AutoMapper case sensitive or insensitive?

安稳与你 提交于 2019-12-04 22:33:51
If object a has a property named 'Id' and object b has a property named 'ID', will AutoMapper correctly map the two properties (without doing a .ForMember(...) call)? The trunk version is now default case-insensitive, and supports multiple naming conventions (camelCase, lowercase_underscore, etc). Look for this in the next version of AutoMapper, which should drop in a couple of days. No, last time I tried it (month or so ago) it was case sensitive. 来源: https://stackoverflow.com/questions/1370128/is-automapper-case-sensitive-or-insensitive