Attribute: [PropertyLength]
Posted by Gerhard Stephan on July 11th, 2006
The PropertyLength attribute is used to specify the length of a database column.
Setting this attribute has no effect on how the ObjectMapper .NET will handle this property, but it defines the length of a database column and therefore it affects the DDL creation.
Look at this example:
[PropertyLength(50)]
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
Furthermore it has an effect on which data type the database column will have. Dependent on the database system you’re using, strings can only be stored up to a specific length of e.g. Oracle 4000 characters. If you want to store longer strings you have to choose other data types that can handle unlimited string size, e.g. CLOBS in Oracle or MEMO fields for Micorosoft Access.
To force the ObjectMapper .NET to use such data types, you have to set the attribute PropertyLength to int.MaxValue.
[PropertyLength(int.MaxValue)]
public string Text
{
get { return text; }
set { text = value; }
}
This example will force the ObjectMapper .NET to use data types like CLOB (Oracle), MEMO (Microsoft Access) or TEXT (Microsoft SQL Server).

July 4th, 2007 at 2:08 pm
[…] {0} = Replacement for the column length specified by the attribute PropertyLength. (No Ratings Yet) Loading … […]