Entity Framework and string as NCLOB on oracle Db Entity Framework and string as NCLOB on oracle Db oracle oracle

Entity Framework and string as NCLOB on oracle Db


I've managed to solve the issue setting the maximum string lenght into 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 the StringLength Orcale creates a NCLOB field that can contain up to 4Gb of data.

Note: Maximum lenght for varchar is 4000 bytes, so we cannot set more than 2000 as MaximumLenght (2 byte per character with Unicode)


Try to configure it 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