不确定如何使用 Fluent NHibernate 从自定义查询中创建对象的属性
我正在尝试映射以下结构:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终做了:
Ended up doing: