2

In .NET 3.5sp1,

I have a table in Sql Server that is defined somehow like this:

CREATE TABLE Employee(
 EmployeeId [int] IDENTITY(1,1) NOT NULL,
 UserName varchar(128) NOT NULL,
 [Name] nvarchar(200) NOT NULL,
 Address xml NULL,
    ...)

I am mapping this table to the ADO.NET Entity Framework. My problem is that the xml column is mapped to a string data type. While this is an expected behavior, I'd like to provide my own custom type.

I tried creating a class

public class Address : IXmlSerializable { ... }

and tried replacing the string data type of the address column to my own Address type, but I can't find a way to make the entity framework understand my custom type.

I read about complex type, but it says that the value itself cannot be null, and in my case it can be null.

Is it possible and how?

1 Answer 1

2

You must use string for the mapped property.

You can, however, add a custom (additional) property in a partial class which translates the string into your custom type. So you might do something like:

public partial class Employee
{
    public Address EmployeeAddress 
    {
        get
        {
            return new Address(this.MappedAddressProperty);
        }
    }
}

You can't use these custom properties in LINQ to Entities, though.

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

1 Comment

I used your idea and I expanded from it. Thank you.

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.