【问题标题】:Mapping xmltype oracle with entity framework 6 code first annotations用实体框架6代码优先注解映射xmltype oracle
【发布时间】:2016-11-21 08:53:41
【问题描述】:

我先尝试使用带有 xmltype 列的代码


在我的数据库中:

TIPOS_GRIFOS

ID_TIPOS_GRIFOS:NUMBER(38,0)

DESC_TIPOS_GRIFOS : VARCHAR2(250 BYTE)

配置:XMLTYPE


在我的代码中:

[Table("TIPOS_GRIFOS")]
public class TiposGrifos : BaseEntity
{
    [Column("ID_TIPOS_GRIFOS"), Key]
    public int IdTiposGrifos { get; set;}

    [Column("DESC_TIPOS_GRIFOS")]
    public string DescTiposGrifos
    { get; set; }

    [Column("CONFIG")]
    public string Config
    { get; set; }

    [NotMapped]
    public XElement xmlData
    {
        get { return XElement.Parse(Config); }
        set { Config = value.ToString(); }
    }}

我可以执行:

   var tiposGrifo = repository.GetById(1);
   tiposGrifo.xmlData = template;

这个对象很好,从数据库中正确导入了数据。但是当我尝试 context.SaveChanges() 时,它会抛出 ORA-932 异常。

谢谢。

PD:我试过了

   [Column(TypeName="xml")]
   public string Config { get; set; }

那没有用。


更新

我发现了问题:

尝试将长度等于或大于 2,000 个字符的字符串绑定到 XMLType 列或参数时,将遇到“ORA-00932:不一致的数据类型:预期 - 得到 NCLOB”错误。 [错误 12630958]

我尝试插入一个小的 xml(少于 2000 个字符),并且我的代码运行良好。但我需要能够插入更大的 xml……有什么解决办法吗?

【问题讨论】:

    标签: c# entity-framework ef-code-first entity-framework-6 xmltype


    【解决方案1】:

    更新:

    这是 Oracle 数据提供者的已知问题。所以你必须等到他们解决这个问题。

    1. 如果字符串包含 2,000 个或更多字符,或包含 4,000 个字符的字节数组,则可能会遇到“ORA-00932:不一致的数据类型”错误 字节或更多长度,绑定在 LINQ/ESQL 的 WHERE 子句中 询问。如果实体属性 映射到 BLOB、CLOB、NCLOB、LONG、LONG RAW、XMLTYPE 列用于 LINQ/ESQL 查询的 WHERE 子句。

    您可以在本文档的 Entity Framework Tips, Limitations, and Known Issues 部分阅读相关内容。

    原帖:

    您可以使用 Fluent API 进行尝试,如下所示。

    public String Config { get; set; }
    
    public XElement xmlData
    {
        get { return XElement.Parse(Config); }
        set { Config = value.ToString(); }
    }
    
    public partial class XmlEntityMap : EntityTypeConfiguration<XmlEntity>
    {
        public FilterMap()
        {
            this.Property(c => c.Config).HasColumnType("xml");
            this.Ignore(c => c.xmlData);
        }
    }
    

    【讨论】:

    • 我也试过了,但没用。还是谢谢你。
    • 请查看更新
    • 谢谢,我会尝试另一种方法来保存数据。
    猜你喜欢
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 2011-04-21
    相关资源
    最近更新 更多