首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有子集合的Nhibernate投影

带有子集合的Nhibernate投影
EN

Stack Overflow用户
提问于 2011-05-27 23:16:49
回答 1查看 1.9K关注 0票数 2

使用DTO2.1,我尝试将一个实体及其子集合投影到一个NHibernate中。我的实体看起来像这样..

代码语言:javascript
复制
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看起来像这样..

代码语言:javascript
复制
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)

代码语言:javascript
复制
  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子集合?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-29 10:58:42

我认为你可能需要做一个MutiQuery,并将DTO的父母和孩子们自己聚集在一起。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6154280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档