XML columns in a Code-First application

后端 未结 4 1634
傲寒
傲寒 2020-12-28 16:38

I\'m trying to create an XML column in Code First. I\'m well aware Entity Framework doesn\'t fully support XML columns, and that it reads them as a string. That\'s fine. I w

4条回答
  •  执念已碎
    2020-12-28 17:14

    Have you tried:

    public String XmlContent { get; set; }
    
    public XElement XmlValueWrapper
    {
        get { return XElement.Parse(XmlContent); }
        set { XmlContent = value.ToString(); }
    }
    
    public partial class XmlEntityMap : EntityTypeConfiguration
    {
        public XmlEntityMap()
        {
            // ...
            this.Property(c => c.XmlContent).HasColumnType("xml");
    
            this.Ignore(c => c.XmlValueWrapper);
        }
    }
    

提交回复
热议问题