Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed length string in Entity Framework?

Is there a way to set the length of a field in EF (6.1)?

I want the following property to be generated as char(2):

public string LanguageId { get; set; }
like image 302
Shimmy Weitzhandler Avatar asked Oct 17 '25 03:10

Shimmy Weitzhandler


1 Answers

You could combine TypeName and StringLength:

[Column(TypeName = "char")]
[StringLength(2)]
public string LanguageId { get; set; }

Within SQL Server it should generate a char(2) column.

like image 127
Pragmateek Avatar answered Oct 19 '25 05:10

Pragmateek