实体框架中的 XML 序列化
实体框架是否能够使用包含一些在 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>
Is Entity Framework able to work with a model object which contains some properties that should be serialized/deserialized into xml during CRUD operations.
Example:
public class Question
{
public string Text { get; set; }
public List<Answers> Answers { get; set; }
}
public class Answers
{
public string Text { get; set; }
}
As a result of insert we should get the following row in the database:
Text | Answers
_____________________________________________________________________________________
myQuestionText | <answers><answer Text="answer1"/><answer Text="answer2"/></answers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的。你必须持久化这个类:
并自己处理序列化和反序列化。您可以使用自定义非映射属性(如果您使用 EDMX 文件,请使用您自己的分部类来定义属性)公开答案列表并隐藏属性的 getter 和 setter 内的序列化和反序列化逻辑。
No. It is not possible. You must persist this class:
And handle serialization and deserialization by yourselves. You can use custom non mapped property (if you are using EDMX file use your own partial class to define the property) exposing list of answers and hide serialization and deserialization logic inside property's getter and setter.