流畅的 NH 和界面映射
我真的很困惑,因为我有几个对象共享使用 FNH 映射的公共接口,如下所示:
.Where(t => (t.BaseType == typeof(Entity) || t.BaseType == typeof(PipelineStep))
&& t.Namespace.StartsWith("BigNose.Core.Domain")
&& !t.IsInterface)
.IgnoreBase<Entity>()
.IgnoreBase<PipelineStep>()
.Override<Project>(map => map.HasMany(p => p.Pipelines).Cascade.All())
.Override<ExpectationProcessingStep>(map =>
{
map.ImportType<IPipelineStep>();
map.ImportType<object>();
})
;
现在这个映射的奇怪之处在于,它似乎允许我使用 Criteria api 查询 IPipelineStep,但不能使用 Linq-to-NH 或 via HQL。例如:
有效(标准):
UoW.Session.CreateCriteria(typeof(IPipelineStep), "p")
.Add(Restrictions.Eq("p.Pipeline", SampleData.PipelineB))
.SetMaxResults(10)
.List<IPipelineStep>()
.ToList();
此 Linq 失败:
UoW.Session.Linq<IPipelineStep>()
.Where(p => p.Pipeline == SampleData.PipelineB)
.ToList();
有例外:
系统.InvalidOperationException: 找不到名为的实体: BigNose.Core.Domain.PipelineSteps.IPipelineStep
但是,奇怪的是,如果没有限制,这可以工作
UoW.Session.Linq<IPipelineStep>()
.ToList();
并且使用 HQL,即使没有限制它也会失败:
UoW.Session.CreateQuery("from IPipelineStep p").List<IPipelineStep>()
例外:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: IPipelineStep 未映射 [来自 IPipelineStep p]
到底发生了什么事,我做错了什么。
预先感谢,克里斯。
Im really confused as I have several objects that share a common interface mapped using FNH like so:
.Where(t => (t.BaseType == typeof(Entity) || t.BaseType == typeof(PipelineStep))
&& t.Namespace.StartsWith("BigNose.Core.Domain")
&& !t.IsInterface)
.IgnoreBase<Entity>()
.IgnoreBase<PipelineStep>()
.Override<Project>(map => map.HasMany(p => p.Pipelines).Cascade.All())
.Override<ExpectationProcessingStep>(map =>
{
map.ImportType<IPipelineStep>();
map.ImportType<object>();
})
;
Now the odd thing about this mapping is that it seems allow me to query against IPipelineStep using Criteria api, but no with Linq-to-NH or via HQL. For example:
Works (Criteria):
UoW.Session.CreateCriteria(typeof(IPipelineStep), "p")
.Add(Restrictions.Eq("p.Pipeline", SampleData.PipelineB))
.SetMaxResults(10)
.List<IPipelineStep>()
.ToList();
This Linq fails:
UoW.Session.Linq<IPipelineStep>()
.Where(p => p.Pipeline == SampleData.PipelineB)
.ToList();
With exception:
System.InvalidOperationException:
Could not find entity named:
BigNose.Core.Domain.PipelineSteps.IPipelineStep
BUT, oddly, with out the restriction this works
UoW.Session.Linq<IPipelineStep>()
.ToList();
And with HQL it fails even without restrictions:
UoW.Session.CreateQuery("from IPipelineStep p").List<IPipelineStep>()
With exception:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException:
IPipelineStep is not mapped [from
IPipelineStep p]
What the heck is going on, and what am I doing soooo wrong.
Thanks in advance, Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 HQL,您需要导入实际的接口,以便它了解它。
在 HBM 文件中包括以下内容:
显然首先要使其有意义。
with HQL you need to import the actual interface so it knows about it.
In an HBM file include the following:
obviously make it make sense first.