Hugo Forte
Hugo Forte

Reputation: 5978

With entity framework, how do I force a sql datatype for my string member

I have a product class, for which the ManufacturerNumber gets generated as nvarchar(max) - how would I go about forcing the code-first framework to make it nvarchar(255)

public class Product : BaseEntity
{
    public string ManufacturerNumber { get; set; }
}

Upvotes: 0

Views: 242

Answers (1)

Eranga
Eranga

Reputation: 32447

Decorate the property with StringLength attribute.

public class Product : BaseEntity
{
    [StringLength(255)]
    public string ManufacturerNumber { get; set; }
}

Upvotes: 1

Related Questions