AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

Problem with text(ntext), varchar > 8000 or nvarchar > 4000 filed #548

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
NHibernate truncated text(ntext), nvarchar, varchar fields.

More info:
http://stackoverflow.com/questions/3701907/how-to-store-a-non-truncated-varcharm
ax-string-with-nhibernate-and-fluent-nhibe

Solution:
Diff:
--- a/NHibernate-v1.2.0.2116/CSharp/HbmMaps/Hbm.cst
+++ b/NHibernate-v1.2.0.2116/CSharp/HbmMaps/Hbm.cst

@@ -37,7 +37,7 @@
        <% } %>

        <% // Properties %>

        <% foreach(EntityMember em in entityManager.MembersNoKeyNoVersion) { %>

-       <property name="<%= em.PropertyName %>" column="<%= em.ColumnSafeName %>" 
<%= GetPropertyType(em.SystemType) %>/>

+       <property name="<%= em.PropertyName %>" column="<%= em.ColumnSafeName %>"  
<%= GetPropertyType(em) %>/>

        <% } %>

        <% // Many-To-One %>

        <% foreach(EntityAssociation association in entityManager.ManyToOne) { %>

@@ -61,10 +61,33 @@
 </hibernate-mapping>

 <script runat="template">

-    public string GetPropertyType(string type)

-    {

-        return type == "System.Xml.XmlDocument"

-            ? String.Format(@"type=""{0}.XmlType, {1}""", this.BaseNamespace, 
this.AssemblyName)

-            : String.Empty;

-    }

+        public string GetPropertyType(EntityMember em)

+        {

+            if (em.SystemType == "System.Xml.XmlDocument")

+            {

+                return String.Format(@"type=""{0}.XmlType, {1}""", 
this.BaseNamespace, this.AssemblyName);

+            }

+

+   

+            //  nvarchar

+            if (em.Column.NativeType == "nvarchar")

+            {

+                if (em.Column.Size > 4000 || em.Column.Size == -1)

+                {

+                    return String.Format(@"type=""{0}""", "StringClob");

+                }

+            }

+            // varchar

+            if (em.Column.NativeType == "varchar")

+            {

+                if (em.Column.Size > 8000 || em.Column.Size == -1)

+                {

+                    return String.Format(@"type=""{0}""", "StringClob");

+                }

+            }

+            // ntext, text

+            return em.Column.NativeType == "ntext" || em.Column.NativeType == 
"text"

+                       ? String.Format(@"type=""{0}""", "StringClob")

+                       : "";

+        }

 </script>

Original issue reported on code.google.com by qdzio....@gmail.com on 28 Jan 2011 at 11:04

GoogleCodeExporter commented 9 years ago
Hello,

Here is the SVN patch for this change in both the C# and VB Version. In the 
future please send us the patch file (if you can) as it is preferred and it 
saves us considerable time in creating the pasted patch line by line.

Thanks
-Blake

Original comment by bniemyjski on 31 Jan 2011 at 4:49

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r2121.

Added more 3.0 type fixes.

Original comment by tdupont...@gmail.com on 31 Jan 2011 at 8:45

GoogleCodeExporter commented 9 years ago
Thanks for the patch, this fix should be in our latest nightly build.
http://community.codesmithtools.com/nightly/NHibernate/

Please let us know how it works for you!

Original comment by tdupont...@gmail.com on 31 Jan 2011 at 9:07