ASP.net MVC5 data Annotation problem

1. I want to use EF6"s Code First to create my application, but I have a field type in the database for text type, I would like to ask whether it can only be expressed as String type in Model at this time, if so, should I specify data annotation StringLength? In addition, I would like to ask, is there a way to represent the database field as an enumerated type or a Set type?
2. My database is sql server 2008R2, please know how to give me some advice, thank you!

Mar.16,2021

1. For fields of text type in the database, you can use the string type in Model to represent them. There is no need to specify StringLength

.

2. For fields of enumerated types, define enumerations in the code, and then identify them with the enumerated type EnumDataType attribute on the property, as follows:

public enum Browser
{
    Chrome,
    Firefox
}

public class YourClass
{
    [EnumDataType(typeof(Browser))]
    public Browser Browser{get;set;}
    ...
}
Menu