Entity Framework and string as NCLOB on oracle Db

I have this model:

public class Teacher { public int TeacherID { get; set; } public string Name { get; set: } public string Surname{ get; set; } } 

and at the first start of the model, it creates a table of my Teachers and DbSet, but for the name and surname (which are the rows), it assigns the column type NCLOB. Now, with the NCLOB type, I cannot perform some operations, such as equals or distincts on my table ....

How can I get MF to set columntype type to varchar?

+5
source share
2 answers

I managed to solve the problem by setting the maximum length of the string in the model

 public class Teacher { public int TeacherID { get; set; } [StringLength(255, MinimumLength = 3, ErrorMessage = "My Error Message")] public string Name { get; set: } [StringLength(255, MinimumLength = 3, ErrorMessage = "My Error Message")] public string Surname{ get; set; } } 

Without StringLength, Orcale creates an NCLOB field that can hold up to 4 GB of data.

Note. The maximum length for varchar is 4000 bytes, so we cannot set more than 2000 as MaximumLenght (2 bytes per character with Unicode)

+6
source

Try setting it up explicitly:

 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Teacher>().Property(x => x.Name).HasColumnType("varchar"); modelBuilder.Entity<Teacher>().Property(x => x.Surname).HasColumnType("varchar"); } 

See Documentation

+4
source

Source: https://habr.com/ru/post/1209341/


All Articles