NHibernate 组件映射(创建标准)
有没有办法为组件创建“别名”?
我有一个“Criteria Builder”,它采用“Address.City”(或“User.Address.City”等)格式的字符串,并基于它创建一个 ICriteria(过滤器和排序)。
我正在使用组件来映射“Address”类,以便它与“User”保留在同一个表中。
我得到的例外是:
NHibernate.QueryException 无法解析属性:城市:MyNamespace.User
如果我尝试不为地址组件创建“别名”,它就可以正常工作。
然而,由于它是一个标准构建器,有没有办法检测“Address”是一个组件并避免调用 criteria.CreateAlias(“Address”)?有解决办法吗?
这与我的问题相同,但解决方案不是对我来说可行(我不会为每个查询手动创建标准)。
任何帮助将不胜感激!
Is there any way to create an “alias” for a component?
I have a “Criteria Builder” that takes strings in the format of “Address.City” (or “User.Address.City”, …) and creates an ICriteria (filters and sorts) based on it.
I am using components to map the “Address” class so it stays in the same table as “User”.
The exception I am getting is:
NHibernate.QueryExceptioncould not resolve property: City of: MyNamespace.User
If I attempt to do not create an “alias” for the Address Component, it works just fine.
However, as it is a criteria builder, is there a way to detect that “Address” is a component and avoid the call criteria.CreateAlias(“Address”)? Any work around?
This is the same question as mine, however the solution is not viable to me (I do not create criteria manually for each query).
Any help would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法为地址创建别名,因为地址不是映射实体。
CreateAlias
和CreateCriteria
之间的唯一区别是前者返回原始 Criteria,而后者返回新的 Subcriteria。因此,您可以为其创建条件的唯一类是已映射的类。由于组件不是映射类,因此您无法围绕它们创建标准。我唯一的建议是让您的 Address 类实现一个空描述符接口(如 IComponent)或使用自定义 ComponentAttribute 对其进行标记。然后,您的 CriteriaBuilder 可以检查为其创建条件的类是否具有此元数据并忽略它。
You can't create an Alias for Address because Address is not a mapped entity. The only difference between
CreateAlias
andCreateCriteria
is that the former returns the original Criteria, whereas the latter returns the new Subcriteria. So the only classes you can create Criteria for are classes that have been mapped. Since components are not mapped classes, you can't create a criteria around them.The only suggestion I have is to have your Address class either to implement an empty descriptor interface like IComponent or mark it with a custom ComponentAttribute. Then your CriteriaBuilder can check whether or not the class it's creating a criteria for has this meta data and ignore it.