NHibernate nvarchar/ntext 截断问题
我使用 nhibernate 在 SQL Server Compact Edition 表中存储应用程序的一些用户设置。
这是映射文件的摘录:
<property name="Name" type="string" />
<property name="Value" type="string" />
名称是常规字符串/nvarchar(50),值在数据库中设置为 ntext
我正在尝试将大量 xml 写入“Value”属性。 我每次都会遇到异常:
@p1 : String truncation: max=4000, len=35287, value='<lots of xml..../>'
我用谷歌搜索了很多,并尝试了许多不同的映射配置:
<property name="Name" type="string" />
<property name="Value" type="string" >
<column name="Value" sql-type="StringClob" />
</property>
这就是一个例子。 其他配置包括“ntext”而不是“StringClob”。 那些不抛出映射异常的配置仍然会抛出字符串截断异常。
这是 SQL CE 的问题(“功能”)吗? 是否可以使用 nhibernate 将超过 4000 个字符放入 SQL CE 数据库中? 如果是这样,谁能告诉我怎么做?
非常感谢!
I'm using nhibernate to store some user settings for an app in a SQL Server Compact Edition table.
This is an excerpt the mapping file:
<property name="Name" type="string" />
<property name="Value" type="string" />
Name is a regular string/nvarchar(50), and Value is set as ntext in the DB
I'm trying to write a large amount of xml to the "Value" property. I get an exception every time:
@p1 : String truncation: max=4000, len=35287, value='<lots of xml..../>'
I've googled it quite a bit, and tried a number of different mapping configurations:
<property name="Name" type="string" />
<property name="Value" type="string" >
<column name="Value" sql-type="StringClob" />
</property>
That's one example. Other configurations include "ntext" instead of "StringClob". Those configurations that don't throw mapping exceptions still throw the string truncation exception.
Is this a problem ("feature") with SQL CE? Is it possible to put more than 4000 characters into a SQL CE database with nhibernate? If so, can anyone tell me how?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我假设这是一个小错字,因为您已经关闭了属性标签两次。 只是指出这一点,以防万一它不是一个错字。
I'm assuming this is a small typo, since you've closed the property tag twice. Just pointing this out, in case it wasn't a typo.
尝试
Try
<property name="Value" type="string" length="4001" />
尝试过:
恐怕
都不起作用...同样的例外 - 它仍然说最大值是 4000。
Tried:
and
Neither worked, I'm afraid... Same exception - it still says that the max value is 4000.
为什么使用子元素语法?
尝试:
Why are you using the sub-element syntax?
try:
在我当前的 SQL CE 和 NHibernate 部署中,我使用的长度为 4001。然后 NHibernate 将这些内容生成为 NTEXT 而不是 NVARCHAR。
尝试一下。
与 NHibernate 和 SQL CE 一起使用的另一件事是:
这至少为我解决了一些其他问题。
On my current deplyoment of SQL CE and NHibernate I use a length of 4001. Then NHibernate generates the stuff as NTEXT instead of NVARCHAR.
Try that.
Another thing to use with NHibernate and SQL CE is:
That solves some other problems for me atleast.
好的,非常感谢此帖子中的 Artur,解决方案如下:
用一个新的驱动程序从 SqlServerCeDriver 继承,并重写 InitializeParamter 方法:
然后,在你的 app.config 中使用这个驱动程序而不是 NHibernate 的驱动程序。
我看到很多其他帖子中人们都遇到了这个问题,并通过更改 sql- 来解决它type 属性为“StringClob” - 正如本线程中所尝试的那样。
我不确定为什么它对我不起作用,但我怀疑这是因为我使用的是 SQL CE 而不是其他数据库。 但是你现在有了!
Okay, with many thanks to Artur in this thread, here's the solution:
Inherit from the SqlServerCeDriver with a new one, and override the InitializeParamter method:
Then, use this driver instead of NHibernate's in your app.config
I saw a lot of other posts where people had this problem, and solved it by just changing the sql-type attribute to "StringClob" - as attempted in this thread.
I'm not sure why it wouldn't work for me, but I suspect it is the fact that I'm using SQL CE and not some other DB. But, there you have it!
阅读您的文章后,此修改使其在我的代码中正常工作
After reading your post this modification got it working in my code