How do I set a field to map to




Updated at 02.04.2010 10:02:29

It seems the best solution is to use DomainUpgradeMode.PerformSafely and then modifying the column type in SQL script.

I suggest to add the column type customization feature in future version, something like


How to submit feature request to DO team?

This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by ccchai.

asked Apr 02 '10 at 04:32

Editor's gravatar image


edited May 31 '11 at 08:04

Dmitri%20Maximov's gravatar image

Dmitri Maximov

One Answer:

Hello, ccchai.

The answer depends on using of a legacy support feature of DataObjects.Net I'll describe both cases.

You use a regular (DO managed) database.

By default string fields have NVARCHAR(N) type, where N is determined by a fancy algorithm.

If you do not specify value for Field.Length property maximal supported length is used:

[Field] // This property is mapped to NVARCHAR(4000)
public string Text { get; set; }

If you specify any value that is less than maximal supported length that value is used:

[Field(Length = 100)] // This property is mapped to NVARCHAR(100)
public string Text { get; set; }

If you specify any value that is greater than maximal supported length than MAX is used:

[Field(Length = 7777)] // This property is mapped to NVARCHAR(MAX)
public string Text { get; set; }

To ensure portability across various RDBMS-es that may have different maximal length of character columns we recommend the following approach:

[Field(Length = int.MaxValue)] // This property is mapped to NVARCHAR(MAX)
public string Text { get; set; }

There is no way to set column type for DateTime field when using non-legacy mode. For SQL Server 2005 DATETIME SQL type is used. For SQL Server 2008 DATETIME2 SQL type is used.

You use a legacy database mode.

In this case DataObjects.Net will try to fit your needs and your database. It does not change your database but only validate it to be compatible with your model. All rules of choosing string types still apply. However, column type can be CHAR(N), VARCHAR(N), NCHAR(N) or NVARCHAR(N) type for limited length string fields. DataObjects.Net will find out what type is used in database and will use that type, but you still need to specify a valid Field.Length value. If you want unlimited length column, its type can be TEXT, NTEXT, VARCHAR(MAX) or NVARCHAR(MAX). For DateTime fields it will accept any of the datetime types: DATE, DATETIME, DATETIME2, SMALLDATETIME.

answered Apr 02 '10 at 09:42

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov

edited May 31 '11 at 08:03

Dmitri%20Maximov's gravatar image

Dmitri Maximov

It is already submitted ;)

I'll create the issue for this and drop a link to it here.

(Apr 02 '10 at 09:42) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Apr 02 '10 at 04:32

Seen: 1,610 times

Last updated: May 31 '11 at 08:04

powered by OSQA