The Entity Framework fills my text fields, although they are not fixed. Length

I am building an MVC3 site using Entity Framework 4 and I am having a problem with fixed-length fields.

When I look at my code during debugging, it shows that MyEntity.Title="Hello name "with a header filled to the maximum length of the field.

This is usually a question of a fixed field length in an EDMX file or the use of a data type charin a base database, not in varchar.. In this case, none of them is correct, however, it is possible that the Initially specified fields had a fixed length. I manually changed each field in EDMX (and the model was regenerated) and the fields were never fixed length in the database (which was the starting point for the application), so I assume that the need to debug the fields is stored somewhere in the Entity Framework configuration and not updated.

The problem arises in new records, when they are added to the database - when the object is created, the Title will be correct when it is created from the database full.

What do I need to do to get rid of the fill, which really wraps my string comparisons if I don't crop everything?

+5
source share
3 answers

It turns out that in the .EDMX file the populated files are still listed as nchar. This was not visible through the Model Editor, the only way to change it is to right-click on the model in Visual Studio and select "open with ..." and then use the XML editor. Offensive fields were as follows:

<Property Name="MyProperty" Type="nchar" Nullable="false" MaxLength="50" />

Changing Typeup nvarcharand starting the template again seemed to fix the problem.

+4
source

. , .

, .

+2

Change the Title field so that the Fixed Length property is true. It probably doesn’t matter by default :)

Make sure you make the changes to the database first and then upgrade edmx.

0
source

All Articles