automapper

Automapper - Bestpractice of mapping a many-to-many association into a flat object

早过忘川 提交于 2019-12-18 17:04:12
问题 I have two entities: Employee and Team . What I want is an EmployeeForm that has the Name of the Team . How can I achieve this using AutoMapper ? My current "solution" is the following: Mapper.CreateMap<Employee, EmployeeForm>() .ForMember(dest => dest.TeamName, opt => opt.MapFrom(x => x.GetTeams().FirstOrDefault() != null ? string.Join(", ", x.GetTeams().Select(y=>y.Name)) : "n/a")); In my opinion this is bad readable. What I would like to have is a generic method where I can pass an entity,

Confusion between DTOs (linq2sql) and Class objects!

做~自己de王妃 提交于 2019-12-18 16:59:33
问题 i have been successfully working with linq2sql and the linq DTOs (the classes that are created by linq2sql) .... I am confused, i have the task of updating an old application and i can see that my DTOs will be used how they should be .... to transport date I am using the repository pattern so i am passing data from the repository to the service via the linq2sql dtos... once i am in the service layer (this is basically my business logic) then I need to pass around class objects .. these class

Confusion between DTOs (linq2sql) and Class objects!

醉酒当歌 提交于 2019-12-18 16:59:02
问题 i have been successfully working with linq2sql and the linq DTOs (the classes that are created by linq2sql) .... I am confused, i have the task of updating an old application and i can see that my DTOs will be used how they should be .... to transport date I am using the repository pattern so i am passing data from the repository to the service via the linq2sql dtos... once i am in the service layer (this is basically my business logic) then I need to pass around class objects .. these class

DDD - how to rehydrate

断了今生、忘了曾经 提交于 2019-12-18 16:58:49
问题 Question : what is the best, efficient and future proof way to rehydrate an aggregate from a repository? What are the pro's and con's of the provided ways and are my perceptions correct? Let's say we have an Aggregate Root with private setters but public getters for accessing state Behaviour is done through methods on the aggregate root. A repository is instructed to load an aggregate. At the moment I see a couple of possible ways to achieve this: set the state through reflection (manual or

DDD - how to rehydrate

我与影子孤独终老i 提交于 2019-12-18 16:58:32
问题 Question : what is the best, efficient and future proof way to rehydrate an aggregate from a repository? What are the pro's and con's of the provided ways and are my perceptions correct? Let's say we have an Aggregate Root with private setters but public getters for accessing state Behaviour is done through methods on the aggregate root. A repository is instructed to load an aggregate. At the moment I see a couple of possible ways to achieve this: set the state through reflection (manual or

How do I use automapper to map a dataset with multiple tables

杀马特。学长 韩版系。学妹 提交于 2019-12-18 16:11:11
问题 DISCLAIMER: this is a copy paste from an older stackoverflow post that isn't available anymore, but I have exaclty the same problem, so it seemed appropriate to repost it as it was never answered. I have a stored procedure that will return 4 result sets (contacts, addresses, email, phones) which is populated into a dataset. I would like to use AutoMapper to populate a complex object. public class Contact { public Guid ContactId { get; set; } public string FirstName { get; set; } public string

How do I use automapper to map a dataset with multiple tables

冷暖自知 提交于 2019-12-18 16:11:02
问题 DISCLAIMER: this is a copy paste from an older stackoverflow post that isn't available anymore, but I have exaclty the same problem, so it seemed appropriate to repost it as it was never answered. I have a stored procedure that will return 4 result sets (contacts, addresses, email, phones) which is populated into a dataset. I would like to use AutoMapper to populate a complex object. public class Contact { public Guid ContactId { get; set; } public string FirstName { get; set; } public string

Using AutoMapper to Map a DataTable to an Object (DTO)

无人久伴 提交于 2019-12-18 15:34:33
问题 I am trying to map a DataTable to an object (DTO) using AutoMappers DynamicMap feature. DataTable dt; dt = new dalAllInvestors().InvestorNameSearch(investorNameSearch); // Look at DynamicMap - Urgent List<dtoAPISimpleInvestor> apiObject = AutoMapper.Mapper.DynamicMap<IDataReader, List<dtoAPISimpleInvestor>>( dt.CreateDataReader()); return apiObject; public class dtoAPISimpleInvestor { public int FirmID { get; set; } public string FirmName { get; set; } public string Type { get; set; } public

How do I use AutoMapper to map multiple subclasses into one class?

本小妞迷上赌 提交于 2019-12-18 15:09:35
问题 Let's assume I have three classes that are subclasses of a base class: public class BaseClass { public string BaseName { get; set; } } public class Subclass1 : BaseClass { public string SubName1 { get; set; } } public class Subclass2 : BaseClass { public string SubName2 { get; set; } } public class Subclass3 : BaseClass { public string SubName3 { get; set; } } I would like to map these to a ViewModel class that looks like this: public class ViewModel { public string BaseName { get; set; }

How inject service in AutoMapper profile class

早过忘川 提交于 2019-12-18 14:46:08
问题 I need to use a service layer in the AutoMapper profile class in ASP.NET Core but when I inject service in the constructor it does not work. For example: public class UserProfile : Profile { private readonly IUserManager _userManager; public UserProfile(IUserManager userManager) { _userManager = userManager; CreateMap<User, UserViewModel>() .ForMember(dest => dest.FullName, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}")); } } And in Startup Class: public class Startup { public