Get the Max Length of a column in Entity Framework

c# entity-framework intellisense linq-to-entities sqldatatypes


When I import a Database to my EDMX Model I get the following information regards to the Max Length

enter image description here

In the image above, I have String column with the Max Length of 250

Is there a way to check (while coding) this max length, without the need to look into the EDMX property?

Sample of how I want the information to be displayed:

If I type something like Class.ColumnName it shows in the Intellisense like a summary information.

3/6/2013 9:51:18 PM

Accepted Answer

One way is to declare it in a class and use this class (not the edmx), example:

[Required(ErrorMessage = "Name is obligatory")]
[StringLength(30, MinimumLength = 3, ErrorMessage = "Name has to have at least 3 characters")]
public string Name { get; set; }

Then I use a user control to check it on the screen. (I know there are better solutions)

PS: The class is a little complex and with a lot of customization, if someone want it I can post in the future.

But, you can check more about it in these links:

StringLength vs MaxLength attributes ASP.NET MVC3 with EF 4.1 Code First
C# How to use DataAnnotations StringLength and SubString to remove text
StringLengthAttribute Class
and String Canonical Functions

5/23/2017 10:32:59 AM

Popular Answer

Intellisense will show whatever text is in the Documentation -> Summary field of the designer. That gives you a few options.

1) You can be really OCD, and upon editing your EDMX in the designer you make sure to always fill out this field.

2) You create some script to parse your .edmx (you can edit it just like any XML file), look for a <Property> element which has a MaxLength specified, and add <Documentation> and <Summary> elements inside, simply stating what the max length is. For example, parse:

<Property Name="USER_NAME" Type="String" MaxLength="50" Unicode="true" FixedLength="false" >


<Property Name="USER_NAME" Type="String" MaxLength="50" Unicode="true" FixedLength="false" >
    <Summary>Max length of 50</Summary>

Then after your edit is complete, all you need to do is rebuild the .Designer.cs/vb by just opening the designer and saving again.

3) Somehow get Visual Studio to know that a class is from an EDMX, then go back to parse the EDMX to get the MaxLength, then update the Intellisense to display accordingly. (I have no idea if this is possible.)

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow