Print Page | Close Window

OData and CodeFirst

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=3241
Printed Date: 13-May-2026 at 10:52am


Topic: OData and CodeFirst
Posted By: cseils
Subject: OData and CodeFirst
Date Posted: 29-Jan-2012 at 9:05pm
Is it possible to enable OData with an entity model created using the Code First method.
I can't see anything in the documentation other that enabling OData using the Model or Database First method.

Thanks



Replies:
Posted By: sbelini
Date Posted: 30-Jan-2012 at 12:54pm
Hi cseils,
 
Yes, it is possible to enable OData and use Code First entities.
Be sure to decorate your Code First entities with the IgnoreProperties and DataServiceKey attributes:
 
[IgnoreProperties(@"EntityAspect", @"AAAA_EntityAspectForSerialization")]
[DataServiceKey(@"MyEntityID")] // where MyEntityID is the entity's key
 
Other than that, you will need to follow steps 2 and 3 described in the  http://drc.ideablade.com/xwiki/bin/view/Documentation/odata-enable#HEnablingOData - Enabling OData topic in the http://drc.ideablade.com/xwiki/bin/view/Documentation/odata-enable#HEnablingOData - DevForce Resource Center .
Also, you might want to implement System.Data.Services.IUpdatable to support OData updates.
 
Regards,
   Silvio.


Posted By: cseils
Date Posted: 30-Jan-2012 at 7:53pm
Thanks Silvio, I tried this out and it all works.



Print Page | Close Window