I am using WebApi 2 with odata 5.3.1.
I am using groupby query, by implementing my own GroupBy() custom function.
http://localhost:51738/odata/Document?$apply=groupby((Category),%20aggregate(Documents/$count%20as%20Total))
But in new database the Category Property is a navigation property & we can achieve it by using $expand.
So how to use $expand query inside groupby query?
I found the way to make group by query compatible with navigation property & it's supporting in odata 5.9.1 library.
In Employee entity there is a Navigation property called Classes,
So we can use group by query like this
http://localhost:51738/odata/Employee?$apply=groupby((Classes/Id)
Related
I am trying to query a table using where like :
Auth::user()
->friends
->where('friend.first_name','LIKE','%'.$firstName.'%')
->all()
The query does work properly without using the LIKE statement only when i add the LIKE keyword it doesn't return any results.
Using all() will work without the builder where() statement.
When grabbing data using the query, use get() instead:
Auth::user()->friends->where('something','LIKE','%'.$something.'%')->get()
I think you are confused between a laravel relation and a eloquent collection. First let me go straight to answer, you would have to do
Auth::user()
->friends()
->where('friend.first_name','LIKE','%'.$firstName.'%')
->get()
To explain what's wrong with your code, ->where('name', 'Like', '%something%') This is a query builder method. You have to use it on the query builder, or Before you actually retrieve the model / model collection.
Auth::user()->friends()
This would give you a relation Illuminate\Database\Eloquent\Relations\HasMany that you can apply where like on.
Auth::user()->friends
This will return you a Illuminate\Database\Eloquent\Collection. And yes, it is a collection, so you will have to use collection method. Take a look at the where method for collection. You can see it only support key => value pair. It does not support "LIKE"
The where method filters the collection by a given key / value pair:
If you want to use achieve a "Like" on collection, you can probably use the filter method, which support custom callback.
The filter method filters the collection using the given callback, keeping only those items that pass a given truth test:
To conclude, when you define a friends "HasMany" relation on User, you have two way to retrieve it.
If you want to apply additional query builder method, you need to use user->friends() which do not return you data, it return you a relation that you can use query builder method. Once you do user->friends, it get you a collection. You cannot apply query builder on that anymore. So basically, user->friends is act the same way as user->friends()->get()
Don't Use all() and use get().
Auth::user()->friends()->where('something','LIKE','%'.$something.'%')->get()
I want a fetchxml that will return a list of Entities, hopefully with Display name and schema name.
Similarly I would like a fetchxml that will return the attributes for an Entity. Also with Display name and Schema name.
I assume there is a way because tools in the XRMToolBox load dropdowns with those value.
Fetchxml is DML query to retrieve data from backend & cannot be used for metadata retrieval. We have to use Organization service or web api to pull Metadata like Entity & attribute definitions.
SO thread 1 & thread 2 will help you to achieve it.
Other useful links:
Query metadata using the Web API
Retrieve data with queries using SDK assemblies
Use the Organization Service to read and write data or metadata
In my plugin, I have a list of entities. I would like to apply the query expression that is passed in the input parameters
QueryExpression query = PluginExecutionContext.InputParameters["Query"];
to a custom list of type entity.
List<Entity> myList;
The entities in the list match the same attributes as the entities used in the plugin context. Is there a way to apply a QueryExpression to a list of entities, or convert a QueryExpression to linq?
QueryExpression is really just a wrapper around FetchXML, which is just an XML schema for queries in Dynamics CRM. If you want to pass in a query as a parameter to a plugin, you could set up an custom entity call "query" or something to that effect and add a field of type textarea to that custom entity called "fetchxml". Then set up the input parameter of your plugin to accept a record of that custom entity instead of a text parameter. this has the added benefit of allowing you to more easily edit the input parameters of the plugin.
Of course, you could always just put the raw fetchXML into the parameter as text, but I can tell you from experience that this will come back to bite you as it is extremely hard to maintain because any changes elsewhere in the system could completely trash your plugin.
If you want to know more about how to get the fetchXML for a certain query or have any other questions, just shoot me a comment.
Is there a way to apply a QueryExpression to a list of entities
Answer is No.
QueryExpression & FetchXML is native of Dynamics CRM, it can be used against CRM service (Database) only. I assume this plugin is on Retrieve message and you are trying to use the system's query expression from that Retrieve service call against your own dataset of entity (List<Entity>). But why?
, or convert a QueryExpression to linq?
No. I know the reverse is possible.
I want to write following query in ASP.NET MVC 4:
select * from Categories where category LIKE '"+result0+"'% ".
Is there any reciprocal of LIKE in Linq query? How would I get same result in MVC4?
You could use Contains or StartsWith. But what are you using to connect to the database? Are you using Entity Framework?
Assuming the existence of an Id property on a category, you could do something like:
Categories.Where(x => x.Id.StartsWith("+result0+"));
That will give you an IEnumerable<Category> of the categories that meets the "search criteria". If you want a List<Category>, you can invoke ToList() on the enumerable.
i want to create web api odata service that return reault type which consist of collection data member and additional members like this service return:
http://services.odata.org/OData/OData.svc/Suppliers?$filter=Address/City eq 'Redmond'
as you can see the result type is consist of collection data member and additional members
can anyone send me a sample how to do it?
i can't succeed to create this kind of complex type and to be able filter the collection items by there values
as yuo can see in this query it return all the result without filter the items
services.odata.org/OData/OData.svc/Suppliers
i want to be able filter this type like this:
services.odata.org/OData/OData.svc/Suppliers?$filter=Address/City eq 'Redmond'
in this query i managed to filter the collection member items and still returning the other data members.
If you just want to implement filters like: services.odata.org/OData/OData.svc/Suppliers?$filter=Address/City eq 'Redmond'
Please check the sample at http://aspnet.codeplex.com/SourceControl/changeset/view/903afc4e11df#Samples%2fNet4%2fCS%2fWebApi%2fODataServiceSample%2fReadMe.txt
It has a supplier and address model with queryable attribute. It should work with the same $filter query.
Odata support was implicit in asp.net webapi RC.
You just had to return a IQueryable from you Actions and mark it with [QueryableAttribute].
Only this much supported querystring based data filtering.
I was a bit disappointed when I saw the [QueryableAttribute] doesnt build in RTM.
In RTM it’s available as a separate package, Microsoft.AspNet.WebApi.OData on Nuget in a preview/alpha form. Full release is coming later this fall. You can grab it from here(http://www.nuget.org/packages/Microsoft.AspNet.WebApi.OData). There is a nice overview post available (http://blogs.msdn.com/b/alexj/archive/2012/08/15/odata-support-in-asp-net-web-api.aspx)