NHibernate 中的 SQL 2008 HierarchyID 支持
搜索了各种 NHibernate 列表,但没有得出明确的答案。 SQL2008 方言 不会似乎支持 HierarchyID 数据类型 - 仅新日期和时间类型。
有人有良好的实施或有效的解决方法吗?我真的很想在我的新应用程序中利用 HierarchyID。 MS 自己的工具非常缺乏对这种有趣且强大的数据类型的支持,因此对于 NHibernate 没有支持我并不感到惊讶。
有 一些 我还没有深入研究的方法。想知道是否有人对什么有效、什么性能更高等有一些经验。
全面披露:我正在使用 Castle ActiveRecord,但这似乎是 NHibernate 问题。
Searched various NHibernate lists and haven't come up with a definitive answer. The SQL2008 dialect doesn't appear to have support for the HierarchyID data type - new date and time types only.
Does anyone have a good implementation or an effective workaround? I'd really like to leverage HierarchyID in a new app of mine. Support for this interesting and powerful data type is sorely lacking in MS's own tools so I'm not shocked that NHibernate doesn't have support.
There are some approaches out there that I haven't delved into yet. Wondering if anyone has some experience in what works, what is more performant, etc.'
Full disclosure: I'm working with Castle ActiveRecord but this seems like an NHibernate issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经对 Needles 的答案进行了测试。这是一个非常好的答案,但需要进行一些更改才能使其发挥作用(至少在 .NET 4 中)。以下是我为我的项目提出的方案:
更新:以下代码可以在 GitHub 上下载,并将在那里进行更新。 NHiberntate.HierarchyId.UserType
SqlHierarchyId IUserType
映射
具有 HierarchyId 的对象
I've given Needles' answer a test run. It's a very good answer but there are some changes needed to make it function (at least in .NET 4). Here's what I've come up with for my project:
Update: the following code can be download over at GitHub and will be updated there. NHiberntate.HierarchyId.UserType
SqlHierarchyId IUserType
Mapping
Object with HierarchyId
免责声明:我不是 NHibernate 专家,但是,我们在即将推出的使用 SQL Server 2008 R2 和层次结构 ID 的项目中将其与 Fluent 一起使用。下面的代码是我们当前在开发环境中使用的代码,尚未经过充分测试/完善。我从其他地方复制了大部分代码(抱歉我丢失了链接!)
您需要创建一个用户定义类型,然后在映射中使用它。下面的映射很流畅,我不知道如何使用 ActiveRecord 来完成它,但我猜它应该是类似的!
用户定义类型
流畅映射
阅读这篇文章:
Castle ActiveRecord:使用 C# 中的类映射到 IUserType
ActiveRecord 使用 [Property] 属性来映射用户定义类型。所以对你来说它看起来像这样:
希望它有帮助!
Disclaimer: Im not an NHibernate expert, however, we are using it with Fluent in an upcoming project which uses SQL Server 2008 R2 and Hierarchy IDs. The code below is what we are using currently on our dev environment and is not fully tested/refined. I copied the majority of the code from elsewhere (sorry I lost the link!)
You need to create a User Defined Type and then use it in your mappings. The mapping below is Fluent, Im not aware how to do it using ActiveRecord but Im guessing it should be similar!
User Defined Type
Fluent Mapping
Reading this post:
Castle ActiveRecord: Map to IUserType wihtin Class in C#
ActiveRecord uses a [Property] attribute to map User Defined Types. So for you it would look something like this:
Hope it helps!