Print Page | Close Window

OData and POCOs

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=2599
Printed Date: 29-Jul-2026 at 8:30pm


Topic: OData and POCOs
Posted By: rallman
Subject: OData and POCOs
Date Posted: 31-Mar-2011 at 8:12am
Is it possible to access POCOs using OData?
If I do not include the IgnoreProperties statement, I receive the following error when invoking the OData service:
The server encountered an error processing the request. The exception message is 'On data context type 'MyEntities', there is a top IQueryable property 'Orders' whose element type is not an entity type. Make sure that the IQueryable property is of entity type or specify the IgnoreProperties attribute on the data context type to ignore this property.'.
I made my POCOs a "first class citizen" by creating a partial class.
[IgnoreProperties("Orders")] //If this is removed, the OData service will not run
 
public partial class MyEntities : IdeaBlade.EntityModel.EntityManager { public IdeaBlade.EntityModel.EntityQuery<Order> Orders { get { return new IdeaBlade.EntityModel.EntityQuery<Order>("Orders", this); } }
}
public partial class Order : IdeaBlade.EntityModel.IKnownType { [Key] public int OrderId { get; set; }
}
Any ideas?



Replies:
Posted By: sbelini
Date Posted: 06-Apr-2011 at 12:08pm
Hi rallman,
 
Yes, it is possible to expose POCOs through OData.
 
Try setting the DataServiceKey attribute in your Order class:
 
 [DataServiceKey("OrderId")]
 public class Order...
 
I have also attached a simple solution demonstrating it.
 
http://www.ideablade.com/forum/uploads/892/ODataWithPoco.zip - uploads/892/ODataWithPoco.zip



Print Page | Close Window