Are there any alternatives to $filter in OData query options ?
Below is my $filter code to select certain data from SharePoint. But due to certain problems with the server, I was unable to execute the query. Are there any alternatives such as $select statement or whichever that does the same function as below ?
ListData?$filter=ContentType eq 'Item'&$top=100
$filter is the only option for filtering data, there is no other way to get only ListData where the ContentType is Item. Alternatively, (and much less performantly), if you really can't do $filter but need to get the data, you could just get back all of the data and do the filtering on the client.
Related
When filtering in fields on D365, we have the filter option of 'is one of' which is more like SQL's where in clause. I'm trying to perform such filter operation using Odata but can't find the right way. Lambda has an any and all but don't know how to throw in a list to compare against.
Try using the In Function.
?$filter=Microsoft.Dynamics.CRM.In(PropertyName=#p1,PropertyValues=#p2)&#p1='name'&#p2=['value','value']
The full list of filter's.
Currently I am writing a query by using LINQ for Sitecore search content. Having a strange is that I cannot search content with keyword 'with'. Everyone have idea for this ?
using (var searchContext = index.CreateSearchContext())
{
var result = searchContext.GetQueryable<SearchResultItem>()
.Where(w =>
w.Content.Contains(searchText)
);
}
The result is empty, I also have try with operator 'like' (w.Content.Lile) but result empty.
I'm not familiar with Lucene.net / sitecore, but it's possible that "with" is a stopword and Lucene removes it when indexing documents. Try including some other keywords in your query to see if you get results. See What is the default list of stopwords used in Lucene's StopFilter? for more details on stopwords.
The code looks fine, the only thing I could see causing an issue would be a case issue. Try this instead:
x.Content.ToUpper().Contains(searchText.ToUpper())
Also, not sure about the Lucene.Net implementation, but this looks like simple Linq-SQL or EF to me, and the .Contains() method is executed locally, not remotely.
I am writing a cypher query in neo4j that merge few seperate queries with'UNION' operator. Now, the final result need to be sorted according to a specific column and I also need to be able to use 'LIMIT' to the final result so that I can fetch based on pagination request.
How to achieve that? adding 'ORDER BY' or 'LIMIT' at the end doesn't seems to work. Can't find a way to wrap the result as temporary set(as in sql queries) either. Any suggestions?
Currently it is not possible to add a ORDER BY or SKIP/LIMIT clause to the global set of UNION.
This is a pending feature request, see https://github.com/neo4j/neo4j/issues/2725
Maybe you can share your query and we can find a way to do it without UNION ?
I Just want to make sure I understand this correctly...
search is an object that contains a querystring.
Repo.Query returns an ObjectQuery<T>.
From my understanding the chained linq statements will filter the results after entity framework has returned all the rows satisfying the query. So really ALL the rows are being returned and THEN filtered in memory. So we are returning a bunch of data that we don't really want. There's about 10k rows being returned so this is kind of important. Just like to get my confusion cleared up.
var searchQuery = Repo.Query(search)
.Where(entity =>
entity.Prop1.ToUpper().Equals(prop1.ToUpper()) &&
entity.Prop2.ToUpper().Equals(prop2.ToUpper()))
.OrderBy(entity => Repo.SortExpression ?? entity.prop1);
Your Repo.Query(string query) function should return IQueryable<T>.
Then you can filter and order without getting all rows first.
IQueryable(Of T) Interface
hope this helps
If this is to SQL, this will most likely create a SQL query and filter on the server and not in memory.
As a matter of fact, the statement above wouldn't actually do anything.
It's only when you iterate over it that the query will be executed. This is why certain providers (like the EF to SQL one) can collapse expression trees into a SQL query.
Easiest way to check is to use LINQPAD or the SQL Profiler to see what query is actually is executed.
I am quite sure that DQL will be the way to go, but I am wondering if Doctrine, i am using Doctrine 2, has someway to return the row count. I won't be using the rows itself, I just want the count.
I'm new to Doctrine2 but it looks like you can simply do this:
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
$count = $query->getSingleScalarResult();
Source (Using Agregate Functions): http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#dql-select-examples
Allowed aggregate functions: http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#aggregate-functions
Here is another interesting point of view about using aggregated functions in DQL
http://doctrine-orm.readthedocs.org/en/latest/cookbook/aggregate-fields.html
Maybe you would avoid the creation of an specific query to obtain an aggregate value. In this case, aggregate fields are a good alternative.