XML data type in EF 4.1 Code First

前端 未结 3 1565
陌清茗
陌清茗 2021-02-05 17:35

I would like to use SQL Server xml type as a column type for an entity class.

According to this thread it\'s possible to map such a column to st

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 18:28

    This's how you do that in Data Annotations, if you want to use Fluent API (and use a mapping class) then:

    public partial class XmlEntityMap : EntityTypeConfiguration
    {
        public FilterMap()
        {
            // ...
            this.Property(c => c.XmlContent).HasColumnType("xml");
    
            this.Ignore(c => c.XmlValueWrapper);
        }
    }
    

    If you use Fluent API by overriding OnModelCreating on DbContext then just change those "this" with modelBuilder.Entity()

提交回复
热议问题