使用 entity framework 6 个代码优先注释映射 xmltype oracle

Mapping xmltype oracle with entity framework 6 code first annotations

我先尝试使用代码 xmltype

的列

在我的数据库中:

TIPOS_GRIFOS

ID_TIPOS_GRIFOS : NUMBER(38,0)

DESC_TIPOS_GRIFOS:VARCHAR2(250 字节)

配置: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 列或范围。 [错误 12630958]

我试过插入一个小的 xml(少于 2000 个字符),我的代码运行良好。但是我需要能够插入更大的 xml... 有什么解决方案吗?

更新:

这是 Oracle 数据提供商的已知问题Issue.So您必须等到他们解决这个问题。

  1. An "ORA-00932 : inconsistent datatypes" error can be encountered if a string of 2,000 or more characters, or a byte array with 4,000 bytes or more in length, is bound in a WHERE clause of a LINQ/ESQL query. The same error can be encountered if an entity property that maps to a BLOB, CLOB, NCLOB, LONG, LONG RAW, XMLTYPE column is used in a WHERE clause of a LINQ/ESQL query.

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

原文Post:

您可以使用 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);
    }
}