1

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>
0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.