Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:23:08+00:00 2026-05-26T06:23:08+00:00

I try to write a XML<>Object Mapper for my Entity Framework Code First class.

  • 0

I try to write a XML<>Object Mapper for my Entity Framework Code First class. Because EF doesn’t support this automatic XML Serialization at the moment I did this to access the “Profile” object property and manipulate the underlying ProfileData string:

[Column(TypeName = "xml")]
public string ProfileData { get; set; }

[NotMapped]
public Profile Profile
{
    get { return ProfileData.DeserializeXml<Profile>(); }
    set { ProfileData = value.SerializeXml(); }
}

Everything works fine but ProfileData.DeserializeXml() returns (of course) a new object, serialized from the ProfileData string. I think the extension method isn’t relevant for my question but I post it anyway:

public static T DeserializeXml<T>(this string xml) where T : class, new()
{
    if(string.IsNullOrWhiteSpace(xml)) return new T();
    var serializer = new XmlSerializer(typeof(T));
    using (var reader = new StringReader(xml))
    {
        try { return (T)serializer.Deserialize(reader); }
        catch { return null; } 
    }
}

When I want to change my object I do this:

var profile = myObject.Profile;
profile.fooVar = "test";

But this will not affect my myObject until I do this:

myObject.Profile = profile;

I know why but I don’t want to do this, I want a… let us say “direct reference” to the underlying ProfileData string with my object wrapper.

Any idea to archive this or is not possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:23:08+00:00Added an answer on May 26, 2026 at 6:23 am

    Why doesn’t your class keep a reference to the Profile object instead, and only serialize or deserialize when requested? In other words, change it to:

    [Column(TypeName = "xml")]
    public string ProfileData
    { 
        get { return Profile.SerializeXml(); }
        set { Profile = value.DeserializeXml<Profile>(); }
    }
    
    [NotMapped]
    public Profile Profile { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first steps with XML and I must send a XML by
This block of code essentially takes a JAXB Object and turns it into a
I have problem with deserialize document to object using XmlSerializer class. Code my function
I'm trying to build an object that looks something like this: public class MyObject
I try to write KSH script for processing a file consisting of name-value pairs,
I try to write to a large file, but it seems like it does
I try to write a simple client/server application (all application is a bluetooth service
I try to write a simple Markdown parser in JavaScript. Therefore I want to
I try to write a macro in clojure that sets up a namespace and
I try to write a simple user script to enlarge the picture when you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.