【问题标题】:XML serialization in Entity Framework实体框架中的 XML 序列化
【发布时间】:2012-01-13 16:10:12
【问题描述】:

实体框架是否能够使用模型对象,该对象包含一些在 CRUD 操作期间应序列化/反序列化为 xml 的属性。

例子:

public class Question
    {
        public string Text { get; set; }
        public List<Answers> Answers { get; set; }
    }

public class Answers
    {
        public string Text { get; set; }
    }

作为插入的结果,我们应该在数据库中获得以下行:

Text           | Answers
_____________________________________________________________________________________
myQuestionText | <answers><answer Text="answer1"/><answer Text="answer2"/></answers>

【问题讨论】:

    标签: xml entity-framework orm xml-serialization poco


    【解决方案1】:

    没有。这不可能。你必须坚持这个类:

    public class Question
    {
        public string Text { get; set; }
        public string Answers { get; set;}
    }
    

    并自行处理序列化和反序列化。您可以使用自定义非映射属性(如果您使用 EDMX 文件,请使用您自己的部分类来定义属性)公开答案列表并在属性的 getter 和 setter 中隐藏序列化和反序列化逻辑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 2015-04-28
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多