0
Blog
    Id
    ...
    List of Posts
    Last Post           <---
    Most Viewed Post    <---

Post
    Id
    ...
    Blog (the blog it belongs to)

List of Posts我曾经在实体中只有一个Blog,但后来我不得不显示一些博客表,如下所示:

Blog Id  | ... |  Last Post  | Most Viewed Post
----------------------------------------------
   1     | ... |  Something  |     Post 1
   1     | ... |  Something  |     Post 10
   1     | ... |  Something  |     Post 5
   1     | ... |  Something  |     Post 4

并仅使用,并将List of Posts其他字段作为 中的属性,Blog从, ETC。)List of PostsLast PostMost Viewed Post

我正在使用NHibernatewith Active RecordwithMySQL以防万一。

4

1 回答 1

0

将计算的属性映射为公式

Refernce(x => x.LastPost).Formula("(Select Max(p.Id) FROM post p WHERE p.BlogId = Id)");

那么您可以在查询中使用它们

于 2013-03-22T12:52:50.477 回答