New Posts New Posts RSS Feed: Complex Type on abstract class aren't saved to the database  (Code first)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Complex Type on abstract class aren't saved to the database (Code first)

 Post Reply Post Reply
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: Complex Type on abstract class aren't saved to the database (Code first)
    Posted: 01-Apr-2012 at 4:34pm
Hi,

If I define a Complex Type in an abstract class in Code First, values from this complex type are never saved to the database.

Below a project test :


Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 02-Apr-2012 at 12:47pm
Hi Walid,
 
You did not decorate the Creation property with the [DataMember] tag.
Doing so will persist the data.
 
Regards,
   Silvio.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 02-Apr-2012 at 1:01pm
Hi,
 
Thank silvio, you were right.
 
Although it's not really clear for me when I should or not put the DataMember attribute with Devforce.
Reading the documentation, I understood I don't have to put the DataMember atttribute all the time, only when at least one property has reduced access in the class.
 
In this exemple, I don't see why it is required. Is it because it's a complex type ?
 
 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 02-Apr-2012 at 4:09pm
Hi Walid,
 
It's not because the property is a complex type, but it's because you are using the [DataContratc] tag in the BaseEntity class itself.
For this reason, you will need to decorate the property with [DataMember].
 
Regards,
   Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down