With DO.Net 3.8.*, we could use the attribute [SqlType(SqlType.Text)] to specify we wanted the underlying column in generated table to be of type "ntext".

Is there an equivalent with DO 4?

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

asked Sep 17 '09 at 15:58

olorin's gravatar image

olorin
358848792


One Answer:

Hello olorin,

In order to map string (or binary) field to SQL column we analyze the value of Length property of Field attribute:

  1. When Length is not specified, e.g.:

[Field] public string Name {get; set;}

we create SQL column of nvarchar type, with max available length. For MS SQL Server it is equal to 4000.

  1. When Length is specified and it is less or equal to max available length for nvarchar type for current Storage provider, e.g.:

[Field(Length = 100)] public string Name {get; set;}

we create SQL column of nvarchar type, with specified Length (100 in this case).

  1. When Length is specified and it is greater than max available length for nvarchar type for current Storage provider, e.g.:

[Field(Length = 4001)] public string Name {get; set;}

we create SQL column of nvarchar(max) type. nvarchar(max) type is the same as ntext type in MS SQL Server 2000.

In order to always get nvarchar(max) type for a field and to be independent of concrete storage provider properties (different database servers have different max available column length for nvarchar type) you may specify length in this way:

[Field(Length = Int32.MaxValue)] public string Name {get; set;}

Hope this helps.

answered Sep 17 '09 at 19:07

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

olorin wrote: Thanks, this absolutely helps!

I will try it.

Regards,

(Sep 17 '09 at 19:07) Editor Editor'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

Subscription:

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

Tags:

×573

Asked: Sep 17 '09 at 15:58

Seen: 1,817 times

Last updated: Sep 17 '09 at 15:58

powered by OSQA