Model-First Entity Framework Max String Length of 4000

一笑奈何 提交于 2019-12-02 12:45:24

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/26361406/model-first-entity-framework-max-string-length-of-4000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!