iqueryable

Wrapping a Web API response in JSON but still having it work with IQueryable and oData

╄→尐↘猪︶ㄣ 提交于 2021-02-07 04:19:47
问题 I have an ASP.NET Web API project, and I want to use oData filters in the project, with the ASP.NET oData preview package. This means I need to use IQueryable as the response type. Unfortunately, the consumer requires the response wrapped like so: { "total": 2, "success": true, "data": [ { object1 }, { object2 } ] } I created a wrapper object which assigns the IQueryable response from my original version to the "data" property, and sets the values for the "total" and "success" properties as

Wrapping a Web API response in JSON but still having it work with IQueryable and oData

风流意气都作罢 提交于 2021-02-07 04:19:21
问题 I have an ASP.NET Web API project, and I want to use oData filters in the project, with the ASP.NET oData preview package. This means I need to use IQueryable as the response type. Unfortunately, the consumer requires the response wrapped like so: { "total": 2, "success": true, "data": [ { object1 }, { object2 } ] } I created a wrapper object which assigns the IQueryable response from my original version to the "data" property, and sets the values for the "total" and "success" properties as

Odata serialization error for SingleResult.Create on an empty IQueryable

我的梦境 提交于 2021-01-27 05:24:36
问题 I'm using OData v4 and trying to get a really simple controller working: Controller: public class ProductController : ODataController { readonly MasterDataEntities db = new MasterDataEntities(); [EnableQuery(PageSize = MaxPageSize)] public IQueryable<Product> Get() { return db.Products; } [EnableQuery] public SingleResult<Product> Get([FromODataUri] string key) { return SingleResult.Create(db.Products.Where(p => p.Code == key)); } } WebApiConfig: ODataModelBuilder builder = new

Odata serialization error for SingleResult.Create on an empty IQueryable

不问归期 提交于 2021-01-27 05:24:09
问题 I'm using OData v4 and trying to get a really simple controller working: Controller: public class ProductController : ODataController { readonly MasterDataEntities db = new MasterDataEntities(); [EnableQuery(PageSize = MaxPageSize)] public IQueryable<Product> Get() { return db.Products; } [EnableQuery] public SingleResult<Product> Get([FromODataUri] string key) { return SingleResult.Create(db.Products.Where(p => p.Code == key)); } } WebApiConfig: ODataModelBuilder builder = new

What exactly does IQueryable mean?

余生颓废 提交于 2021-01-22 08:28:18
问题 I'm not sure I understand what exactly IQueryable is. I understand that it doesn't get me all the entities and puts the constraint part in memory but executes it as part of the command it sends to the database. Please correct me if I'm mistaken and tell me, why should my repository functions return IQueryable and not a simple List ? 回答1: An IQueryable is not actually a collection of entities, rather it describes how to obtain that collection. The data is never retrieved from the source until

linq to sql ExecuteQuery() as IQueryable

北慕城南 提交于 2020-02-03 09:16:48
问题 ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable? 回答1: Well, you can call AsQueryable , but it won't do any good. The problem is that when you use ExecuteQuery , the query isn't composable because LINQ to SQL doesn't "understand" it as such. One of the core purposes of IQueryable<T> is to allow the various aspects of a query to be composed together and then LINQ to SQL can convert them into a single SQL query. That just doesn't work when one of the

linq to sql ExecuteQuery() as IQueryable

牧云@^-^@ 提交于 2020-02-03 09:16:40
问题 ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable? 回答1: Well, you can call AsQueryable , but it won't do any good. The problem is that when you use ExecuteQuery , the query isn't composable because LINQ to SQL doesn't "understand" it as such. One of the core purposes of IQueryable<T> is to allow the various aspects of a query to be composed together and then LINQ to SQL can convert them into a single SQL query. That just doesn't work when one of the

Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?'

我们两清 提交于 2020-01-31 04:06:25
问题 var cityList = from country in doc.Element("result") .Element("cities") .Descendants("city") select new { Name = country.Element("name").Value, Code = country.Element("code").Value, CountryCode = int.Parse(country .Element("countrycode") .Value) }; foreach(var citee in cityList) { City city = new City(); city.CountryID = from cnt in db.Countries where cnt.DOTWInternalID == citee.CountryCode select cnt.ID; } I'm getting an error on the second query as seen in the title of this post. I tried

Using Expression.Call with Queryable.Select with a type known only at runtime

本秂侑毒 提交于 2020-01-23 17:49:07
问题 I am trying to select a column from an IEnumerable collection that has a type known only to me at runtime. The only way I can think of using this is using LINQ expressions to build a dynamic call to Queryable.Select . However, I'm having a lot of trouble figuring out the proper syntax to accomplish this. An example of how I would do this in the happy-go-lucky world of knowing everything I need at compile time, my code would look like this: ' Create an IEnumerable(Of String) Dim strings = {

Linq To Sql return from function as IQueryable<T>

廉价感情. 提交于 2020-01-21 07:35:06
问题 Ok, I have managed to get the following working public IQueryable getTicketInformation(int ticketID) { var ticketDetails = from tickets in _context.tickets join file in _context.file_objects on tickets.ticket_id equals file.source_id where tickets.ticket_id == ticketID select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename }; return ticketDetails.AsQueryable(); } I went ahead and created my own class (myObject) containing the primitives ticket_id, title, care_of