1

I'm just looking into the possibility of using AutoMapper in our application. Its working well however I have this situation. Given this class

public class Foo
{
    public string Name { get; set; }
    public Bar Bar { get; set; }
}

I can map to it fine using the default configuration

Mapper.CreateMap<Something, Foo>();

and then calling

.Project().To<Foo>();

(applied to an IQueryable)

However in one situation I don't want to map the Bar property through. I want it to be ignored. Is it possible to change the mapping configuration for this one time? If so how?

4

1 回答 1

2

不,这是不可能的,尤其是考虑到您使用的是 EF 映射方式。您实际上是在谈论表达式树的条件构建。解决此问题的最佳方法是创建两个单独的目标类型,可能使用继承来根据需要添加其他字段。

于 2013-09-30T15:56:08.073 回答