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 1112803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:45:52+00:00 2026-05-17T02:45:52+00:00

I’m in charge to migrate our own DAL to a solution based on Entity

  • 0

I’m in charge to migrate our own DAL to a solution based on Entity Framework 4 but, before I can do it, I need to be sure it’s possible to translate all our “constructs” to this new technology.

One of the biggest issues I’m having is the possibility to read a field and build a custom type. Valid examples could be a bit mask saved in a BIGINT field, a list of mail addresses saved as a CSV list in a NVARCHAR field or an XML field containing aggregated data not worth to have their own table/entity. Basically the serialization mechanism is not fixed.

Let’s take the classic “Address” example.

public class Address
{
    public string Street {get; set;}
    public string City {get; set;}
    public string Zip {get; set;}
    public string Country {get; set;}
}

and let’s suppose we want to save it in an XML field using this template:

<address>
  <street>Abrahamsbergsvägen, 73</street>
  <city>Stockholm</city>
  <zip>16830</zip>
  <country>Sweden</country>
</address>

The question basically is: does exist a method to override how EF4 serializes and deserializes the content of a field mapped to a property of an entity?

  • 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-17T02:45:52+00:00Added an answer on May 17, 2026 at 2:45 am

    I found this solution. It’s not as clean as I wished but it seems it’s impossible to get anything better.

    given this base entity,

    public class Institute
    {
        public int InstituteID { get; set; }
        public string Name { get; set; }
        // other properties omitted
    }
    

    I added in the database an XML field called Data containing some strings using this simple template

    <values>
      <value>Value 1</value>
      <value>Value 2</value>
      <value>Value 3</value>
    </values>
    

    In the entity I added these properties and I mapped the database field “Data” to the property “DataRaw”.

    protected string DataRaw
    {
        get
        {
            if (_Data == null)
                return _DataRaw;
            else
                return new XElement("values", from s in Data select new XElement("value", s)).ToString();
        }
        set
        {
            _DataRaw = value;
        }
    }
    
    private string _DataRaw;
    private string[] _Data;
    
    public string[] Data
    {
        get
        {
            if (_Data == null)
            {
                _Data = (from elem in XDocument.Parse(_DataRaw).Root.Elements("value")
                         select elem.Value).ToArray();
            }
            return _Data;
        }
    
        set
        {
            _Data = value;
        }
    }
    

    This solution works. Here is the sample code:

    class Program
    {
        static void Main(string[] args)
        {
            var ctx = new ObjectContext("name=TestEntities");
    
            var institute = ctx.CreateObjectSet<Institute>().First();
    
            System.Console.WriteLine("{0}, {1}", institute.InstituteID, institute.Name);
            foreach (string data in institute.Data)
                System.Console.WriteLine("\t{0}", data);
    
            institute.Data = new string[] { 
                "New value 1",
                "New value 2",
                "New value 3"
            };
    
            ctx.SaveChanges();
        }
    }
    

    Does anyone have a better solution?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.