How do I set a column in SQL Server to varchar(max) using ASP.net EF Codefirst Data Annotations?

前端 未结 5 886
南笙
南笙 2021-02-06 20:31

I\'ve been searching around the web trying to figure out the right syntax to have Entity Framework Code First create my table with a column: varchar(max).

This is what I

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 21:33

    [Column(TypeName = "varchar(MAX)")] results in varchar(Max) in the database. If you have a custom convention setting strings MaxLength to 100, modelBuilder .Properties() .Configure(c => c.IsUnicode(false).HasMaxLength(100)); you need to include the MaxLength attribute [Column(TypeName = "varchar(MAX)"), MaxLength]. If you dont, you will get varchar(MAX) in the database but validation will throw for more that 100 characters

提交回复
热议问题