Is there an attribute I can use when creating a table ? I tried [StringLength]
but it seems to be ignored.
public class EntityRegister { public int Id { get; set; } [StringLength(450)] public string Name { get; set; } }
Data Annotations - StringLength Attribute in EF 6 & EF Core It specifies the maximum characters allowed for a string property which in turn sets the size of a corresponding column ( nvarchar in SQL Server) in the database.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
An . edmx file is an XML file that defines a conceptual model , a storage model , and the mapping between these models. An . edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.
alternatively, you can manually do it on Fluent API
use HasMaxLength(450)
or if you want Data Annotation
, use MaxLength
and MinLength
attributes
public class EntityRegister { public int Id { get; set; } [MaxLength(450)] public string Name { get; set; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With