Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104692

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; }

Upvotes: 4

Views: 4856

Answers (1)

Pragmateek
Pragmateek

Reputation: 13354

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.

Upvotes: 8

Related Questions