本文介绍了实体框架和字符串作为NCLOB在oracle Db上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有这个模型:

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

当Model First运行时,它会创建我的Teachers表和DbSet,但是对于名称和姓氏(它们是字符串),它将NCLOB类型分配给列。
现在,使用NCLOB类型,我不能在我的表上做一些像equals或distincts的操作....

and when Model First run, it creates my Teachers table and DbSet, but for Name and Surname (which are string) it assigns NCLOB type to the column.Now, with NCLOB type I cannot do some operations like equals or distincts on my table....

如何强制MF将columntype设置为varchar

How can I force MF to set columntype to varchar?

推荐答案

我设法解决了将模型中最大字符串长度设置为
的问题

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; }
}

没有StringLength Orcale创建一个NCLOB字段,最多可以包含4Gb的数据。

Without the StringLength Orcale creates a NCLOB field that can contain up to 4Gb of data.

注意:varchar的最大长度为4000字节,所以我们不能设置2000以上为MaximumLenght(每个字符为Unicode为2个字节)

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

这篇关于实体框架和字符串作为NCLOB在oracle Db上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 18:52