Fixed length string in Entity Framework?

.net entity-framework entity-framework-6

Question

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; }
1
3
1/9/2015 1:08:11 AM

Accepted Answer

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.

7
1/9/2015 1:08:19 AM


Related Questions





Related

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