为什么 UserRolesPartRecord 不是从 Orchard CMS 中的 ContentPartRecord 派生的?
Why is UserRolesPartRecord not derived from ContentPartRecord in Orchard CMS?
我想用IContentManager
查询一些满足以下条件的用户
- 发表
- 特定角色成员
通过使用 IContentManager.Query(VersionOptions)
我可以轻松实现条件 1,但我找不到实现条件 2 的方法,因为所有其他通用扩展方法仅限于记录 类 派生自 ContentPartRecord
.
为什么 UserRolesPartRecord
不是派生自 ContentPartRecord
从而阻碍我在内容管理器查询中使用它的原因?
因为老了。上次我不得不对用户执行复杂的查询时,我不得不求助于 HQL,而不是 ContentManager.Query
。查看这些博客文章:https://weblogs.asp.net/bleroy/querying-orchard-in-hql, https://weblogs.asp.net/bleroy/joining-orchard-part-records-in-hql, https://weblogs.asp.net/bleroy/getting-orchard-content-items-out-of-hql。最终结果看起来像这样:
var session = _sessionLocator.For(typeof (UserPartRecord));
const string fromTables =
"FROM Orchard.ContentManagement.Records.ContentItemVersionRecord ItemVersion"
+ " JOIN ItemVersion.ContentItemRecord Item"
+ " JOIN Item.UserPartRecord User"
+ " WHERE ItemVersion.Published = true"
+ " AND User.UserName IS NOT NULL";
const whereClause =
"User.Id NOT IN (SELECT Role.UserId FROM Orchard.Roles.Models.UserRolesPartRecord Role)";
const orderBy = "ORDER BY User.UserName";
var pageQuery = session.CreateQuery(
"SELECT DISTINCT User.Id, User.UserName "
+ fromTables
+ " AND " + whereClause
+ " " + orderBy)
.SetFirstResult(pager.GetStartIndex())
.SetMaxResults(takeNum);
var ids = pageQuery.List<int>();
var results = contentManager
.GetMany<UserPart>(ids, VersionOptions.AllVersions, QueryHints.Empty);
我想用IContentManager
查询一些满足以下条件的用户
- 发表
- 特定角色成员
通过使用 IContentManager.Query(VersionOptions)
我可以轻松实现条件 1,但我找不到实现条件 2 的方法,因为所有其他通用扩展方法仅限于记录 类 派生自 ContentPartRecord
.
为什么 UserRolesPartRecord
不是派生自 ContentPartRecord
从而阻碍我在内容管理器查询中使用它的原因?
因为老了。上次我不得不对用户执行复杂的查询时,我不得不求助于 HQL,而不是 ContentManager.Query
。查看这些博客文章:https://weblogs.asp.net/bleroy/querying-orchard-in-hql, https://weblogs.asp.net/bleroy/joining-orchard-part-records-in-hql, https://weblogs.asp.net/bleroy/getting-orchard-content-items-out-of-hql。最终结果看起来像这样:
var session = _sessionLocator.For(typeof (UserPartRecord));
const string fromTables =
"FROM Orchard.ContentManagement.Records.ContentItemVersionRecord ItemVersion"
+ " JOIN ItemVersion.ContentItemRecord Item"
+ " JOIN Item.UserPartRecord User"
+ " WHERE ItemVersion.Published = true"
+ " AND User.UserName IS NOT NULL";
const whereClause =
"User.Id NOT IN (SELECT Role.UserId FROM Orchard.Roles.Models.UserRolesPartRecord Role)";
const orderBy = "ORDER BY User.UserName";
var pageQuery = session.CreateQuery(
"SELECT DISTINCT User.Id, User.UserName "
+ fromTables
+ " AND " + whereClause
+ " " + orderBy)
.SetFirstResult(pager.GetStartIndex())
.SetMaxResults(takeNum);
var ids = pageQuery.List<int>();
var results = contentManager
.GetMany<UserPart>(ids, VersionOptions.AllVersions, QueryHints.Empty);