使用DTO2.1,我尝试将一个实体及其子集合投影到一个NHibernate中。我的实体看起来像这样..
public class Application
{
public int Id {get;set;}
public string Name {get;set;}
public List<ApplicationSetting> Settings {get;set;}
// A bunch of other properties that I don't want in the DTO
}
public class ApplicationSetting
{
public int Id {get;set;}
public string Name {get;set;}
public string Code {get;set;}
// A bunch of other properties that I don't want in the DTO
}我的DTO看起来像这样..
public ApplicationDto
{
public int Id {get;set;}
public string Name {get;set;}
public List<ApplicationSettingDto> Settings {get;set;}
}
public class ApplicationSettingDto
{
public int Id {get;set;}
public string Name {get;set;}
public string Code {get;set;}
}我只选择应用程序和项目的代码是这样的(使用Nhibernate 2.1和nhLambdaExtensions)
var applicationAlias = new Application();
var criteria = Session
.Add<Application>(a => a.Id == id);
int? Id = null;
string Name = null;
criteria
.SetProjection
(
Projections.Distinct(
Projections.ProjectionList()
.Add(LambdaProjection.Property<Application>(a => a.Id).As(() => Id))
.Add(LambdaProjection.Property<Application>(a => a.Name).As(() => Name))
)
);
criteria.SetResultTransformer(Transformers.AliasToBean(typeof(ApplicationDto)));
var contract = criteria.UniqueResult<ApplicationDto>();我的问题是,如何将ApplicationSettings实体中的一些属性投影到ApplicationSettingsDto子集合?
发布于 2011-05-29 10:58:42
我认为你可能需要做一个MutiQuery,并将DTO的父母和孩子们自己聚集在一起。
https://stackoverflow.com/questions/6154280
复制相似问题