我的目标对象有一个参数构造器,我需要将一个对象传递给它以供内部使用。 如何将其传递给ProjectTo
-映射
CreateMap<SomeEntity, SomeModel>();
-投射
var param = new SomeContructorParam();
await context.SomeEntities
.ProjectTo<SomeModel>() -- PASS PARAM here? how so
.ToListAsync();
目标对象
public class SomeModel
{
private readonly SomeContructorParam ctorParam;
public SomeModel(SomeContructorParam ctorParam)
{
this.ctorParam = ctorParam;
}
...
}
public class SomeContructorParam
{
...
}
答案 0 :(得分:1)
经过测试。
映射:
SomeContructorParam emptyParm = null
CreateMap<SomeEntity, SomeModel>()
.ConstructUsing(src => new SomeModel(emptyParm));
投影
var param = new SomeContructorParam();
await context.SomeEntities
.ProjectTo<SomeModel>(new { emptyParm = param })
.ToListAsync();