NHibernate - does it make sense to set the length attribute for properties / columns?

usually a property / column definition is as follows:

<property name="DocumentSummary" column="DocumentSummary" length="100" type="String">
   <column name="DocumentSummary" />
</property>

I assumed that NHibernate would validate the data using the length attribute before inserting / updating a row. Unfortunately, this is apparently a false assumption. So the question is, is NHibernate using the length attribute for anything? Does it make sense to set it for each property?

+3
source share
3 answers

It uses it to create a sql database definition. Take a look at the SchemaExport class.

+4
source

, . . , Java Hibernate, , NHibernate.

+1

, Length , , .

NVARCHAR(MAX). Length, NHibernate , 4096 .

( Mapping-By-Code, 2017 : -)

classMapper.Property(
                        tickerFeed => tickerFeed.StaticTickerText,
                        propertyMapper =>
                        {
                             propertyMapper.Column("StaticTickerText");
                             propertyMapper.Length(int.MaxValue);
                        }
                    );

, , IPropertyMapper.Type, , .

classMapper.Property(
                        tickerFeed => tickerFeed.StaticTickerText,
                        propertyMapper =>
                        {
                             propertyMapper.Column("StaticTickerText");
                             propertyMapper.Type(NHibernateUtil.StringClob);
                        }
                    );

We are done with the option propertyMapper.Typeas it is more explicit.

0
source

Source: https://habr.com/ru/post/1704532/


All Articles