I am trying to create my first NHibernate project, so maybe I am doing something stupid here, but for several days I was Googling and still had no joy.
I have an Article object that has various properties:
public class Article { public virtual string Title { get; set; } public virtual string Body { get; set; } }
I use the free configuration to load the mappings:
configuration.Mappings(m => m.AutoMappings.Add((AutoMap.AssemblyOf<Article>()) .Conventions.Add(DefaultCascade.All()) .UseOverridesFromAssemblyOf<SchemaConfigurationController>())
Completion:
public class ArticleOverrideMapping : IAutoMappingOverride<Article> { public void Override(AutoMapping<Article> mapping) {
I tried each of the commented lines (roughly in order when I found a possible solution online). I can force SQL Server to create an nvarchar (max) column, and if I use SQL Management Studio, I can insert a LOT (185 602 words - the biggest test) in the Body column. My problem is trying to make it save from MVC site using NHibernate.
There are two main mistakes:
String or binary data would be truncated. The statement has been terminated.
This will happen if I do not set the override to ".Length (Int32.MaxValue)".
The second error that occurs (when the length is specified):
The length of the string value exceeds the length configured in the mapping/parameter.
I am rather confused as to what I should be doing at this moment. My goal is to be able to store a very large string (the whole article) in SQL Server (and SQLite for testing, nvarchar (max) did not like SQLite) and get it back (and edit) to the MVC Website.
UPDATE
Follow @Cymen link I tried
.CustomSqlType("nvarchar(max)").Length(Int32.MaxValue).Nullable();
but this leads to an error:
The length of the string value exceeds the length configured in the mapping/parameter.
when I was just trying to save 1201 words (the whole word is "test"). When I added the length at the end of the above display ".Length (Int32.MaxValue)", I still got the same error.
Update
wanted to confirm which versions i am using:
FluentNHibernate.1.3.0.733 NHibernate.3.3.1.4000 Microsoft.AspNet.Mvc.4.0.20710.0
final update
Kiren had it right, I completely forgot that I took this property and ran markdownsharp on it on the server and populated the second property on the server. So this was the second property that I did not display, it was just an explosion, sorry.