This is probably a very simple question but I have been looking for hours for a solution.
I am attempting to create a queryable odata controller. I cannot seem to get the [Queryable] attribut to resolve correctly. The controller works fine without the attribute. Any help is appreciated! I am sure that something is not referenced. I am setup
to use the nightly builds but actually using the 2.22.13 published version of the WebAPI.OData
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http.OData;
using System.Web.Http.OData.Query;
using WII.Info.Models;
namespace WII.Info.Controllers
{
public class SalesController : EntitySetController<SalesOrder, int>
{
static List<SalesOrder> salesOrders = new List<SalesOrder>()
{
new SalesOrder() { key = 1, CustomerID = "1", CustomerName = "Customer 1", SalesOrderNumber = "001", Terms = "Net 10", Amount = (decimal)123.15},
new SalesOrder() { key = 2, CustomerID = "2", CustomerName = "Customer 2", SalesOrderNumber = "002", Terms = "Net 10", Amount = (decimal)23.15},
new SalesOrder() { key = 3, CustomerID = "3", CustomerName = "Customer 3", SalesOrderNumber = "003", Terms = "Net 10", Amount = (decimal)3.15}
};
[Queryable]
public override IQueryable<SalesOrder> Get()
{
return salesOrders.AsQueryable();
}
protected override SalesOrder GetEntityByKey(int key)
{
return salesOrders.FirstOrDefault(s => s.key == key);
}
}
}
You'll need to include the appropriate reference within your page to the System.Web.Http namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http.OData;
using System.Web.Http.OData.Query;
using WII.Info.Models;
using System.Web.Http; //This is what you need
You can also likely fully qualify the attribute as well (without the need of adding the using statement) by using :
[System.Web.Http.Queryable]
Just as an additional note, if you ever run into issues where you need to Resolve a reference (or want to try to resolve it), try the following steps :
Right-click on the item in question in Visual Studio (in this case your [Queryable] attribute)
Select the Resolve option (if available)
The Resolve options should offer to automatically qualify the reference or add the appropriate using statement.
Keep in mind this will only work if you have the appropriate library referencing within your Project.</div>
I appreciate the feedback. I did not add any references and have read before about the resolve options in vs. I do not have that option when I right click. I appreciate the knowledge of the absolute reference also.
darsys
Member
2 Points
5 Posts
[Queryable] Attribute
Feb 26, 2013 10:51 PM|LINK
This is probably a very simple question but I have been looking for hours for a solution.
I am attempting to create a queryable odata controller. I cannot seem to get the [Queryable] attribut to resolve correctly. The controller works fine without the attribute. Any help is appreciated! I am sure that something is not referenced. I am setup to use the nightly builds but actually using the 2.22.13 published version of the WebAPI.OData
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http.OData; using System.Web.Http.OData.Query; using WII.Info.Models; namespace WII.Info.Controllers { public class SalesController : EntitySetController<SalesOrder, int> { static List<SalesOrder> salesOrders = new List<SalesOrder>() { new SalesOrder() { key = 1, CustomerID = "1", CustomerName = "Customer 1", SalesOrderNumber = "001", Terms = "Net 10", Amount = (decimal)123.15}, new SalesOrder() { key = 2, CustomerID = "2", CustomerName = "Customer 2", SalesOrderNumber = "002", Terms = "Net 10", Amount = (decimal)23.15}, new SalesOrder() { key = 3, CustomerID = "3", CustomerName = "Customer 3", SalesOrderNumber = "003", Terms = "Net 10", Amount = (decimal)3.15} }; [Queryable] public override IQueryable<SalesOrder> Get() { return salesOrders.AsQueryable(); } protected override SalesOrder GetEntityByKey(int key) { return salesOrders.FirstOrDefault(s => s.key == key); } } }Kiran Challa
Participant
1442 Points
281 Posts
Microsoft
Re: [Queryable] Attribute
Feb 26, 2013 11:21 PM|LINK
Queryable attribute is part of System.Web.Http namespace..so need to add "using System.Web.Http".
Kiran Challa
Rion William...
All-Star
27906 Points
4618 Posts
Re: [Queryable] Attribute
Feb 26, 2013 11:47 PM|LINK
As Kiran mentioned,
You'll need to include the appropriate reference within your page to the System.Web.Http namespace.
You can also likely fully qualify the attribute as well (without the need of adding the using statement) by using :
Just as an additional note, if you ever run into issues where you need to Resolve a reference (or want to try to resolve it), try the following steps :
Keep in mind this will only work if you have the appropriate library referencing within your Project.</div>
darsys
Member
2 Points
5 Posts
Re: [Queryable] Attribute
Feb 27, 2013 12:52 PM|LINK
I appreciate the feedback. I did not add any references and have read before about the resolve options in vs. I do not have that option when I right click. I appreciate the knowledge of the absolute reference also.
darsys
Member
2 Points
5 Posts
Re: [Queryable] Attribute
Feb 27, 2013 12:53 PM|LINK
Thanks!!
Rion William...
All-Star
27906 Points
4618 Posts
Re: [Queryable] Attribute
Feb 27, 2013 02:14 PM|LINK
If the Resolve didn't work then you will need to ensure that you have that reference added to your Project under References -> Add References.
Glad that you got the problem all taken care of :)