NHibernate 针对的标准测绘

发布于 2024-08-21 04:18:40 字数 733 浏览 2 评论 0原文

我有一个项目模型,它具有 IProjectWorker 类型的属性,这可以是单个用户或团队。在 Castle ActiveRecord 中,它的定义如下:

[Any(typeof(int), MetaType = typeof(string), TypeColumn = "WorkerType", IdColumn = "WorkerID", Cascade = CascadeEnum.None)]
[Any.MetaValue("USER", typeof(User))]
[Any.MetaValue("TEAM", typeof(Team))]
public IProjectWorker Worker { get; set; }

现在我需要能够搜索工作人员姓名包含某些文本的项目。我最初的反应是这样的:

query
   .CreateAlias("Worker", "Worker")
   .Add(Restrictions.InsensitiveLike("Worker.WorkerName", SearchText, MatchMode.Anywhere));

但这给了我一个错误——“任何类型都没有唯一引用的持久化器”。这是有道理的,它不知道如何处理连接到两个不同表的搜索。

我可以为每个表创建两个不同的别名并在它们之间执行 Restrictions.Or() 吗?我尝试了一下,但不太正确。或者是否有其他方法可以使用我缺少的标准来做到这一点?或者我必须使用 HQL 来代替?

I have a Project model that has a property of type IProjectWorker, this could either be a single User or a Team. In Castle ActiveRecord it's defined like this:

[Any(typeof(int), MetaType = typeof(string), TypeColumn = "WorkerType", IdColumn = "WorkerID", Cascade = CascadeEnum.None)]
[Any.MetaValue("USER", typeof(User))]
[Any.MetaValue("TEAM", typeof(Team))]
public IProjectWorker Worker { get; set; }

Now I need to be able to search for projects where the worker's name contains some text. My initial reaction was something like this:

query
   .CreateAlias("Worker", "Worker")
   .Add(Restrictions.InsensitiveLike("Worker.WorkerName", SearchText, MatchMode.Anywhere));

But this gives me an error-- "any types do not have a unique referenced persister". This makes sense, it doesn't know how to handle joining to the two different tables for the search.

Can I make two different aliases for each table and do a Restrictions.Or() across them? I tried it, but couldn't quite get it right. Or is there some other way to do this using criteria that I'm missing? Or am I going to have to use HQL instead?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文