New Posts New Posts RSS Feed: OData and POCOs
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

OData and POCOs

 Post Reply Post Reply
Author
rallman View Drop Down
Newbie
Newbie


Joined: 20-Apr-2010
Posts: 5
Post Options Post Options   Quote rallman Quote  Post ReplyReply Direct Link To This Post Topic: OData and POCOs
    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?


Edited by rallman - 31-Mar-2011 at 8:13am
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: 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.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down