Print Page | Close Window

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

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3367
Printed Date: 13-May-2026 at 8:02am


Topic: Complex Type on abstract class aren't saved to the database (Code first)
Posted By: Walid
Subject: Complex Type on abstract class aren't saved to the database (Code first)
Date 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 :

uploads/998/ComplexTypeNotSaved.rar - uploads/998/ComplexTypeNotSaved.rar




Replies:
Posted By: sbelini
Date 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.


Posted By: Walid
Date 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 ?
 
 


-------------


Posted By: sbelini
Date 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.



Print Page | Close Window