Page 1 of 1

Specifying the length of a string field

Posted: Wed 07 May 2014 13:50
by edowney
So I've created my first model and went to gen the database. So far so good. I then go and run the tsql to create the tables, etc at which point it sort of falls on its face. All strings are converted to varchar(MAX). How do I change that in the model? Some of the keys are strings and SQL Server won't let you use MAX as a value for key fields.

Re: Specifying the length of a string field

Posted: Thu 08 May 2014 16:02
by Shalex
You are working with Devart Entity Model (Entity Framework), aren't you?

We will investigate the possibility of processing the problem with varchar entity key column without specified Max Length by Entity Developer automatically and notify you about the result.

As a solution, please set the Max Length attribute for your varchar entity key columns in SSDL via interface of Entity Developer manually.

Re: Specifying the length of a string field

Posted: Fri 16 May 2014 10:44
by Shalex
The behaviour is changed in the latest (5.7.357) build of Entity Developer: now by default VARCHAR(8000) / NVARCHAR(4000) columns, instead of VARCHAR(MAX) / NVARCHAR(MAX), correspond to the string properties in the model.

It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=29584.

Re: Specifying the length of a string field

Posted: Thu 05 Jun 2014 20:07
by KrustyTJ
It's possible to set VARCHAR(MAX) explicit? The column length property allow only int values. I cannot generate sql script with VARCHAR(MAX) now.

Re: Specifying the length of a string field

Posted: Fri 06 Jun 2014 10:59
by Shalex
Please choose the varchar(max) SSDL type instead of varchar for the corresponding column in Storage Column Editor of Entity Developer. Does this help?

Re: Specifying the length of a string field

Posted: Fri 13 Jun 2014 09:16
by PeterM
Could it be a nice idea to also add a type String (max) to the list you can select for the field. Because then the Regenerate Storage and Mapping doesn't break those fields.

Re: Specifying the length of a string field

Posted: Mon 16 Jun 2014 08:20
by PeterM
Or, another option is to make this dependant on what you set as the max Length in the Validation section.
Either way I think it is quite confusing that you need to specify it on the storage level whereas there is no difference when you look at it from the perspective of the Type you set for the property.

When specifying fields for NH I know there is a String and a StringClob type to clarify this when defining the property.

Is there a reason other than simple ease that you have chosen to go with setting the default to be varchar(8000) instead of actually
We will investigate the possibility of processing the problem with varchar entity key column without specified Max Length by Entity
, which would suggest that you change this behaviour _only_ for Key columns.

Re: Specifying the length of a string field

Posted: Tue 17 Jun 2014 14:17
by KrustyTJ
Shalex wrote:Please choose the varchar(max) SSDL type instead of varchar for the corresponding column in Storage Column Editor of Entity Developer. Does this help?
It doesn't help. I have StringClob property type and set column SQL type to varchar(max). But Entity Developer still generate ALTER COLUMN ... NVARCHAR(4000).

Re: Specifying the length of a string field

Posted: Wed 18 Jun 2014 11:05
by Shalex
1. For Model-First approach, be aware of the following option which allows applying default mapping in SSDL automatically: Model Settings > Synchronization > Mapping > "Enable automatic synchronization of storage part and mapping of the model with its conceptual part". When this option is turned on, the corresponding storage columns with default mapping are created automatically in SSDL once you create an entity property in CSDL. You can also change default mapping for particular storage columns manually.

2. If you run Regenerate Storage and Mapping, Entity Developer reapplies default mapping for all storage columns in SSDL so the changes made over default mapping will be lost.

3. Both Update Database From Model and Generate Database Script From Model wizards create DDL basing on the datatypes in SSDL part of the model. If you select the Regenerate Storage option on the first step of the Update Database From Model (or Generate Database Script From Model) wizard, Entity Developer reapplies default mapping for all storage columns in SSDL first and, then, generates DDL basing on the new (default mapping) datatypes in SSDL.

JIC: Database First (not Model First) mapping for the newly created models can be customized via Visual Studio > Tools > Entity Developer > Options > Server Options > SQL Server (or Entity Developer > Tools > Options > Server Options > SQL Server).

@PeterM
Please turn on "Enable automatic synchronization of storage part and mapping of the model with its conceptual part" and do not invoke Regenerate Storage and Mapping to preserve your custom mapping.

@KrustyTJ
Make sure that (a) the datatype of the corresponding column in SSDL is varchar(max) and (b) you do not check the Regenerate Storage option on the first step of the Update Database From Model (or Generate Database Script From Model) wizard.