asp.net-web-api-odata

Translate OData queries to SQL

家住魔仙堡 提交于 2019-12-06 08:01:19
I'm in an ODataController and I have an ODataQueryOptions (and all the rest of it). I know that the source of the data is a table in SQL Server. However, my EF model (that was used by the WEB API framework to route the HTTP request to my controller) is typeless, i.e., I don't have a POCO class. Normally -- if I did have a POCO class -- the framework would magically write SQL from the OData query so that the paging, filtering, and sorting is done on the database and not in memory on the web server. You can use Database.Log on the DbContext to see the SQL that's generated from LINQ statements

The path template on the action in controller is not a valid OData path template

六眼飞鱼酱① 提交于 2019-12-05 01:36:26
I am getting the following error: The path template 'GetClients()' on the action 'GetClients' in controller 'Clients' is not a valid OData path template. Resource not found for the segment 'GetClients'. My controller method looks like this public class ClientsController : ODataController { [HttpGet] [ODataRoute("GetClients(Id={Id})")] public IHttpActionResult GetClients([FromODataUri] int Id) { return Ok(_clientsRepository.GetClients(Id)); } } My WebAPIConfig file has builder.EntityType<ClientModel>().Collection .Function("GetClients") .Returns<IQueryable<ClientModel>>() .Parameter<int>("Id");

The complex type 'MyData.AssetReading' refers to the entity type 'MyData.Asset' through the property 'Asset'

余生颓废 提交于 2019-12-04 22:01:05
Looking at setting up Web API odata and trying to expose the data out of our edmx to it. The problem is that every time i add an entity to the OdataConventionBuilder I get a big nasty error message on load saying: The complex type 'MyData.AssetReading' refers to the entity type 'MyData.Asset' through the property 'Asset' It seems for relations defined in the edmx is bombing the webapi odata out about a complex type. Any ideas on how to get around this as the edmx is huge and a rejig of it is pretty much out of the question. Is there a property that I need to set on the Builder.EntitySet or the

How to properly integrate OData with ASP.net Core

折月煮酒 提交于 2019-12-04 09:56:14
问题 I'm trying to create a new ASP.NET Core project with a "simple" web api using OData and EntityFramework. I have previously used OData with older versions of ASP.NET. I have set up a controller with only a simple get function. I've managed to get it working with basic OData commands as filter and top, but I can't get the expand command working. I think it's because I can't quite figure out how to set it up in Startup.cs. I have tried a lot of things including following some odata samples from

Applying Distinct to OData query

爷,独闯天下 提交于 2019-12-03 07:50:33
I want to get a list of distinct values from my OData endpoint. But distinct or group by isn't supported yet. My URI query looks something like this GET /odata/Products?$select=foo & $top=10 & $count=true & distinct=true My Controller [EnableQuery] public IQueryable<FooBarBaz> Get(ODataQueryOptions<FooBarBaz> queryOptions, bool distinct) { //I've tried the following return Repository.AsQueryable().Distinct(); // and return Repository.AsQueryable().GroupBy(x => x.Foo); // and IQueryable query = queryOptions.ApplyTo(Repository.AsQueryable()); return query.Distinct(); // Can't call .Distinct()

How to properly integrate OData with ASP.net Core

可紊 提交于 2019-12-03 04:25:30
I'm trying to create a new ASP.NET Core project with a "simple" web api using OData and EntityFramework. I have previously used OData with older versions of ASP.NET. I have set up a controller with only a simple get function. I've managed to get it working with basic OData commands as filter and top, but I can't get the expand command working. I think it's because I can't quite figure out how to set it up in Startup.cs. I have tried a lot of things including following some odata samples from Github: https://github.com/OData/WebApi/tree/vNext/vNext/samples/ODataSample.Web https://github.com

Controlling what is returned with an $expand request

末鹿安然 提交于 2019-11-30 13:03:00
So, using the ODataController , you get to control what gets returned if somebody does /odata/Foos(42)/Bars , because you'll be called on the FoosController like so: public IQueryable<Bar> GetBars([FromODataUri] int key) { } But what if you want to control what gets returned when somebody does /odata/Foos?$expand=Bars ? How do you deal with that? It triggers this method: public IQueryable<Foo> GetFoos() { } And I assume it just does an .Include("Bars") on the IQueryable<Foo> that you return, so... how do I get more control? In particular, how do I do it in such a way that OData doesn't break

Web API OData Security per Entity

一曲冷凌霜 提交于 2019-11-29 19:26:01
Background: I have a very large OData model that is currently using WCF Data Services (OData) to expose it. However, Microsoft has stated that WCF Data Services is dead and that Web API OData is the way they will be going. So I am researching ways to get Web API OData to work as well as WCF Data Services. Problem Setup: Some parts of the model do not need to be secured but some do. For example, the Customers list needs security to restrict who can read it, but I have other lists, like the list of Products, that any one can view. The Customers entity has many many associations that can reach it

Web API OData Security per Entity

蓝咒 提交于 2019-11-28 15:49:50
问题 Background: I have a very large OData model that is currently using WCF Data Services (OData) to expose it. However, Microsoft has stated that WCF Data Services is dead and that Web API OData is the way they will be going. So I am researching ways to get Web API OData to work as well as WCF Data Services. Problem Setup: Some parts of the model do not need to be secured but some do. For example, the Customers list needs security to restrict who can read it, but I have other lists, like the

How to get Web API OData v4 to use DateTime

风流意气都作罢 提交于 2019-11-27 18:10:52
I have a fairly large data model that I want to expose using Web API OData using the OData V4 protocol. The underlying data is stored in a SQL Server 2012 database. That database has many DateTime columns in it. As I was wiring it up I got an error that System.DateTime is not supported. So here is my question, what can I do to get my DateTime columns to be seen in the OData feed? NOTE: I am not able to go back and change all my columns to DateTimeOffset columns. I tried changing the type of the column in the Entity Framework edmx, but it gave me this error: Member Mapping specified is not