Question

I posted this once, but I was a bit too vague in my information, so I am trying again.

nHibernate/Fluent nHibernate seems to be truncating, or 'stripping' certain characters from strings that I submit to my database. For example, if I submit the string This\nis\na\nblock\nof\ntext\n\with\nreturns, the \n symbol represents the carriage returns. I want these to stay intact, because later, when the data is read back out, that is when it will be parsed by MarkdownDeep

However, I have noticed that the \n symbol specifically gets 'stripped' when the database does its commit. I have performed debugging all the way up to ISession.SaveOrUpdate(object) and I can confirm that the data is unaltered up to the point I can visibly follow the debugging. But then I go and look at the record in the database, and it has been stripped of this symbol.

If I use String.Replace("\n","\\n")) on the text, it will actually work right. But this does not seem like an intelligent way to go about storing everything. This means I have to continuously remember what fields may have this problem and do in-between logic.

Is there a setting I am missing in nHibernate/Fluent nHibernate that is forcing it to strip this data?

Debugged Code Path

Following the path of my code, it goes like this.

ASP.NET MVC View (textarea) -> This\nis\na\nblock\nof\ntext\n\with\nreturns

ASP.NET MVC Model (Json) -> This\nis\na\nblock\nof\ntext\n\with\nreturns

ASP.NET MVC Controller Parameter -> This\nis\na\nblock\nof\ntext\n\with\nreturns

ISession.SaveOrUpdate -> This\nis\na\nblock\nof\ntext\n\with\nreturns

Database Record -> This is a block of text with returns

So the problem is obviously happening at the ISession level.

Was it helpful?

Solution

How are you actually verifying that the \n's aren't in the database record? You will not see a \n visually when you look at the record in sql management studio. It will look like a space if you just query the data. Copy and paste that data into notepad++ and show all the characters that exist in that string (I'm betting you will see the new lines).

Whenever you manually insert \n in the table view like you describe above this is not a special character. It is the actual text '\n'. Please note that '\n' != char(10). One is a special character and the other is just text.

OTHER TIPS

Use this add-on to log produced sql's. then you can find where is the problem. + If you are displaying the data on a web page, don't forget to use replace("\n","<br/>").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top