English 中文(简体)
图一. 甲型六氯环己烷清单
原标题:Mapping from list down to object with AutoMapper
  • 时间:2010-08-12 19:35:39
  •  标签:
  • automapper

I m New with AutoMapper and have a problem I mtries to resolution.

如果我有这样的来源:

public class Membership
{
    public int MembershipId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string OrganizationName { get; set; }
    public List<Address> Addresses { get; set; }
}

地址类别也这样看:

public class Address
{
    public int AddressId{ get; set; }
    public int RefAddressTypeId { get; set; }
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public bool IsPreferredAddress { get; set; }
}

我的目的地是:

public class UserInformationModel
{
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Organization { get; set; }
    public string EmailAddress { get; set; }
    public PhysicalAddress BillingAddress { get; set; }
    public PhysicalAddress ShippingAddress { get; set; }
}

目的地地址类别是:

public class PhysicalAddress
{
    public AddressType AddressType{get; set;}
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string PostalCode { get; set; }

}

我建立了这样的地图:

Mapper.CreateMap<MinistryMattersIntegration.BusinessObjects.Entities.Cokesbury.Membership, UserInformationModel>()
      .ForMember(dest => dest.Organization, opt => opt.MapFrom(src=>src.OrganizationName));

这是为了加入用户信息网站,但现在我需要找到工作地址。 不过,值得注意的是,目的地是单一账单地址和单一航运地址,而在原始模型中,所有地址都作为清单储存。 你在名单上找到航运和账单地址的方式是看重RefressTypdId和IsPnewaddress。 可能只有一个首选地址。

因此,我的问题是,你们如何获得自动申请者来做这种制图? 是否可行,或者我更不了解常规的制图法?

最佳回答

您希望使用Custom Valueator AutoMapper的特征。 因此,你设立了习惯决心者,从您的名单上向您的单一实体绘制地图,使用“IsPnew”旗号找到。

这些文件对习俗决定者非常好,因此,你应当从那里对文件进行精确的划分。

问题回答

暂无回答




相关问题
AutoMapper With Generic Type Inheritance

I m trying to map CustomerDTO with my domain entity ICustomer with AutoMapper. Everything works fine for first inheritance level but not for the others. I m using Interfaces for my domain model since ...

C# automapper nested collections

I have a simple model like this one: public class Order{ public int Id { get; set; } ... ... public IList<OrderLine> OrderLines { get; set; } } public class OrderLine{ public int ...

Automapper, generics, dto funtimes

Here s the deal: I have a report designer where users can create reports based on some predefined datasets. They can select a set of columns to include in the report and then, when the report is ran, ...

Problem with AutoMapper in IIS7 when using signed assemblies

I am trying to use AutoMapper with web application running on IIS 7. The intended use it so map domain types defined in an external dll to view models defined in the IIS application. This works fine ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

热门标签