Saturday, 7 September 2013

Prevent EF 5 from generating a property

Prevent EF 5 from generating a property

I'm using EF5 database first with partial classes. There's a property in
my partial class which contains n object which is stored as a column in my
database containing XML data. I want to handle the
serialization/deserialization of this object when the EF tries to
read/write it with a custom getter/setter.
Is it possible to expose the column in my partial class and map it using
the EF, without auto-generating a property for it?
ie:
public SomeObject BigComplexObject { get; set; } // forms etc in my app
use this
public string BigComplexObjectString // when the EF tries to read/write
the column, my custom getter/setter kicks in
{
get { return this.BigComplexObject.ToXmlString(); }
set { this.BigComplexObject = new BigComplexObject(value); }
}
At present, the EF is auto-generating a member for the column so I'm left
with two.

No comments:

Post a Comment