简体   繁体   English

用NHibernate CreateQuery插入Json TEXT数据

[英]Inserting Json TEXT data with NHibernate CreateQuery

I need to save a serialized Json string of varying length to a TEXT column in a Sybase database. 我需要将长度不同的序列化Json字符串保存到Sybase数据库中的TEXT列中。

Due to the datatype being TEXT, I cannot use a stored procedure. 由于数据类型为TEXT,因此无法使用存储过程。

NHibernate's CreateQuery seems like it will work BUT the single quotation marks in the Json string is breaking the Query. NHibernate的CreateQuery似乎可以工作,但Json字符串中的单引号会打断查询。

As a last resort, I'm considering calling Replace on the single quotation marks and replacing it with a different symbol and then doing the reverse (Restoring the quotes) on the other end before decoding the data. 作为最后的选择,我考虑在单引号上调用Replace并将其替换为其他符号,然后在解码数据之前在另一端进行相反操作(还原引号)。

Is there a better way of achieving what I need to do? 有没有实现我需要做的更好的方法?

Used string.Replace to replace the single (') quotes with double single quotes (''). 使用字符串替换将双引号('')替换为单引号(')。

This escapes the single quotes when creating the Sybase SQL query. 创建Sybase SQL查询时,这转义了单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM