不确定如何使用 Fluent NHibernate 从自定义查询中创建对象的属性

发布于 2024-10-15 09:59:59 字数 1083 浏览 1 评论 0原文

我正在尝试映射以下结构:

public class Tag {
   public Guid Id {get;set;}
   public DateTime ActivatedDate {get;set;}
}

public class History {
   public Guid Id {get;set;}
   public TypeEnum Type {get;set;}
   public Guid ContentID {get;set;}
   public DateTime HistoryDate {get;set;}
}

Tag.ActivatedDate 实际上由 填充(从历史记录中选择前 1 个 HistoryDate,其中 ContentID = {tagid} && Type = 'Activated' order by HistoryDate desc

I我真的不知道如何使用 Fluent NHibernate 映射它

我的映射是:

public TagMapping() {
   Table("Tags");
   Id(x => x.Id)     
}

public HistoryMapping() {
   Table("History");
   Id(x => x.Id);
   Map(x => x.Type).CustomeType<TypeEnum>();
   Map(x => x.ContentID);
   Map(x => x.HistoryDate);
}

我不知道如何映射 Tag.ActivatedTop

基本上寻找:

SELECT tag.Id,
       (select top 1 HistoryDate from History 
               where ContentID = tag.Id 
                AND Status = 'Activated' 
        order by HistoryDate desc) As ActivatedDate
FROM Tags tag

I am trying to map the following structure:

public class Tag {
   public Guid Id {get;set;}
   public DateTime ActivatedDate {get;set;}
}

public class History {
   public Guid Id {get;set;}
   public TypeEnum Type {get;set;}
   public Guid ContentID {get;set;}
   public DateTime HistoryDate {get;set;}
}

Tag.ActivatedDate is actually populated by (select top 1 HistoryDate from History where ContentID = {tagid} && Type = 'Activated' order by HistoryDate desc

I'm really not sure how to Map this with Fluent NHibernate.

My mappings are:

public TagMapping() {
   Table("Tags");
   Id(x => x.Id)     
}

public HistoryMapping() {
   Table("History");
   Id(x => x.Id);
   Map(x => x.Type).CustomeType<TypeEnum>();
   Map(x => x.ContentID);
   Map(x => x.HistoryDate);
}

I'm not sure how to map Tag.ActivatedTop

Basically looking for:

SELECT tag.Id,
       (select top 1 HistoryDate from History 
               where ContentID = tag.Id 
                AND Status = 'Activated' 
        order by HistoryDate desc) As ActivatedDate
FROM Tags tag

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-10-22 09:59:59

最终做了:

  Map(x => x.ActivatedDate)
                .ReadOnly()
                .Formula(
                    string.Format(
                        "(select top 1 h.HistoryDate from History h where h.ContentID = Id AND h.Status = 'Activated' order by h.HistoryDate desc)"));

Ended up doing:

  Map(x => x.ActivatedDate)
                .ReadOnly()
                .Formula(
                    string.Format(
                        "(select top 1 h.HistoryDate from History h where h.ContentID = Id AND h.Status = 'Activated' order by h.HistoryDate desc)"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文