Entity framework 使用automapper映射到实体框架对象的更自动的方法

Entity framework 使用automapper映射到实体框架对象的更自动的方法,entity-framework,automapper,Entity Framework,Automapper,我将相当多的WCF数据契约映射到实体框架类 每节课我都要做这样的事情: Mapper.CreateMap<MyContractClass, MyDalClass>() .ForMember(x => x.EntityKey, opt => opt.Ignore()) .ForMember(x => x.SomeAssociation, opt => opt.Ignore()) .ForMember(x => x.SomeAssoc

我将相当多的WCF数据契约映射到实体框架类

每节课我都要做这样的事情:

Mapper.CreateMap<MyContractClass, MyDalClass>()
    .ForMember(x => x.EntityKey, opt => opt.Ignore())
    .ForMember(x => x.SomeAssociation, opt => opt.Ignore())
    .ForMember(x => x.SomeAssociationReference, opt=> opt.Ignore())
    // Repeat 
    // the 
    // last 
    // /two 
    // lines 
    // for 
    // every 
    // single 
    // association
    // (Some classes have a lot of associations)
    ;
Mapper.CreateMap()
.ForMember(x=>x.EntityKey,opt=>opt.Ignore())
.ForMember(x=>x.SomeAssociation,opt=>opt.Ignore())
.ForMember(x=>x.SomeAssociationReference,opt=>opt.Ignore())
//重复
//
//最后
///两个
//线条
//为了
//每一个
//单身
//联想
//(有些班级有很多联系)
;
有没有更简单的方法?有什么方法可以排除EntityFramework中的所有额外内容

还是只需要手工完成


注意:我已经对POCO模板进行了广泛的评估,它不适用于我的场景。请不要只是建议使用Automapper,而不是Automapper。

假设您的合同类没有关联属性,您可以在一条语句中忽略它们:

Mapper.CreateMap<MyContractClass, MyDalClass>().IgnoreAllNonExisting();
Mapper.CreateMap().IgnoreAllNonExisting();

假设您的合同类没有关联属性,您可以在一条语句中使用忽略它们:

Mapper.CreateMap<MyContractClass, MyDalClass>().IgnoreAllNonExisting();
Mapper.CreateMap().IgnoreAllNonExisting();

我正在使用T4模板从EDMX模型生成映射。到目前为止,这很有效,节省了我很多时间。这个想法来自于。您可以下载他的模板并对其进行自定义,以适应您的场景。

我正在使用T4模板从EDMX模型生成映射。到目前为止,这很有效,节省了我很多时间。这个想法来自于。您可以下载他的模板并对其进行自定义,以适合您的场景。

您可以使用比AutoMapper更简单的模板。你不必写地图,也不必配置它。它全部由工具自动生成。

您可以使用比AutoMapper更简单的工具。你不必写地图,也不必配置它。这一切都是由工具自动生成的