3

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.

Michel Ayres
  • 5,891
  • 10
  • 63
  • 97

2 Answers2

1

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

[Column("Name")]
[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

Community
  • 1
  • 1
Michel Ayres
  • 5,891
  • 10
  • 63
  • 97
0

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" >

into:

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

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.)

Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48