DeeRain
DeeRain

Reputation: 1354

XML serialization in Entity Framework

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>

Upvotes: 1

Views: 705

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364369

No. It is not possible. You must persist this class:

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

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.

Upvotes: 1

Related Questions