Mare Infinitus
Mare Infinitus

Reputation: 8162

Model-First Entity Framework Max String Length of 4000

For a project I have a SQL Server CE 3.5 database.

It is accessed / created through entity framework with the model-first approach.

Now I have some String typed columns in my EDMX, which have the max length specified.

EDMX declaration
<Property Name="Description" Type="nvarchar" Nullable="false" MaxLength="Max" />

The generated code (*.sqlce file) shows that from the max-length string column in the model a nvarchar(4000) column is generated.

.edmx.sqlce file (sql to create the database)
[Description] nvarchar(4000)  NULL,

This is not long enough for the strings that shall be stored in these columns.

In some code-first approach solutions to this issue I have seen that the ntext datatype can help, because it does not have the 4000 chars limit.

How can this be achieved in a model-first environment?

Upvotes: 1

Views: 2620

Answers (1)

ErikEJ
ErikEJ

Reputation: 41749

enter image description here

Add FixedLength="false" - so:

<Property Name="Text" Type="String" Nullable="false" MaxLength="Max" FixedLength="false" />

Then it is generated as ntext using the standard template

Of course you must connect to a SQL Server Compact database file when the wizard comes up for this to work. You can install my SQL Server Compact Toolbox to enable this in VS 2012 or newer

Upvotes: 1

Related Questions