I know that it gives some solutions for this error already but I dont find out why I got this error. When I load the List without filtered it works.
if (searchString != "") {
query = _pagedDataQueryProcessor.GetDefaultQuery<Data.Entities.Password>()
.Where(
Restrictions.Disjunction()
.Add(Restrictions.On<Data.Entities.Password>(x => x.Name).IsLike(searchString))
.Add(Restrictions.On<Data.Entities.Password>(x => x.Description).IsLike(searchString))
.Add(Restrictions.On<Data.Entities.Password>(x => x.PasswordText).IsLike(searchString))
);
}
I found out what the problem was
Solution:
if (searchString != "") {
query = _pagedDataQueryProcessor.GetDefaultQuery<Data.Entities.Password>()
.Where(
Restrictions.Disjunction()
.Add(Restrictions.On<Data.Entities.Password>(x => x.Name).IsLike("%" + searchString + "%"))
.Add(Restrictions.On<Data.Entities.Password>(x => x.Description).IsLike("%" + searchString + "%"))
.Add(Restrictions.On<Data.Entities.Password>(x => x.PasswordText).IsLike("%" + searchString + "%"))
);
What did i changed? i didn't had the "%".
Here I want to filter a list but when I wrote something in the input i always got a empty list.
searchstring is the filtered word
data.entities.password is the list on the db
Can someone help me I dont know what i make wrong.
You need to add wildcards or add a second argument to IsLike.
...IsLike("%" + searchString + "%"))
You can put the wildcard anywhere in the string, e.g. only at the beginning or only at the end.
Or
...IsLike(searchString, MatchMode.Anywhere)
You can also use MatchMode.Start or MatchMode.End.
Related
I'm trying to render an Infragistics Grid as part of my view in my MVC application. However, I'm trying to do the following:
#(Html.Infragistics()
.Grid(Model)
.ID("grid")
.Width("100%")
.Height("500px")
.PrimaryKey("ID")
.AutoGenerateColumns(false)
.AutoGenerateLayouts(false)
.Columns(column =>
{
column.For(x => x.omkt).HeaderText("OMKT").Width("30%");
column.For(x => x.dmkt).HeaderText("DMKT").Width("30%");
column.For(x => x.ibu).HeaderText("IBU").Width("20%");
column.For(x => x.count_total).HeaderText("COUNT_ALL").Width("20%");
})
.Features(features =>
{
features.Sorting().Type(OpType.Remote);
features.Paging().Type(OpType.Remote);
features.Filtering().Type(OpType.Remote);
})
.DataSourceUrl(Url.Action("GetMarketAreaData?ibu=" + ViewBag.IBU + "&sort=" + ViewBag.sort + "&startDate=" + ViewBag.startDate + "&endDate=" + ViewBag.endDate))
.Render()
)
The problem is on the DataSourceUrl line, where it's transforming all the ? and & characters into their escape sequences. Using \ doesn't work either, as I get a parser error for an unrecognized escape sequence. The reason why I need this, though, is because all of those are passed in as parameters into the controller function in order to pull the correct data.
As a result, I'm getting a 400 error when pulling the data. Is there any way to force the action to recognize ? characters for ? characters?
Found the answer: I needed to pass in a second parameter into Url.Action with all the parameters.
.DataSourceUrl(Url.Action("GetMarketAreaData", new { ibu = ViewBag.IBU, sort = ViewBag.sort, startDate = ViewBag.startDate, endDate = ViewBag.endDate }))
I want to get all PartitionStates by name where it exactly meets the partitionName or starts with it when containing a ..
This is the query I have
return session.QueryOver<PartitionState>()
.Where(p => p.Name == partitionName)
.WhereRestrictionOn(p => p.Name).IsLike(partitionName + ".", MatchMode.Start)
.OrderBy(p => p.StartDate).Desc
.Take(1)
.SingleOrDefault<PartitionState>();
The above query produces an AND expression, but i want it to be an OR.
In SQL it should look like this:
SELECT TOP 1 *
FROM PartitionState
WHERE (Name = #partitionName OR Name like #partitionName+'.%')
ORDER BY StartDate DESC
It seems there is no built in method, but it is possible to pass a restriction into where method.
return session.QueryOver<PartitionState>()
.Where(Restrictions.Or(
Restrictions.Where<PartitionState>(p => p.Name == partitionName),
Restrictions.On<PartitionState>(p => p.Name).IsLike(partitionName + ".", MatchMode.Start)))
.OrderBy(p => p.StartDate)
.Desc.Take(1)
.SingleOrDefault<PartitionState>();
I need to filter a LiceneQuery by a users' favourited and blocked tags. I've got this working when a user has some favourite and blocked tags but I'm struggling with the case where the user has no favourite or blocked tags. I believe I need to use the equivalent of a MatchAllDocsQuery but I can't see how to achieve this through the RavenDB client API.
This works fine when the user has one or more favourite and one or more blocked tags:
string favesQuery = String.Join(" OR ", user.FavouriteTags.Select(x => String.Format("Tags:{0}", x)));
string blockedQuery = String.Join(" AND ", user.BlockedTags.Select(x => String.Format("-Tags:{0}", x)));
var articles = RavenSession.Advanced
.LuceneQuery<Article>("AllDocs/ByTags")
.Include(x => x.Author)
.Where(favesQuery)
.Boost(0.5m)
.Where(blockedQuery)
.OrderByDescending(x => x.DatePublished);
The immediate issue I'm getting, is Missing where clause, but this is because the String.Join returns an empty string when user.FavouriteTags is empty. Can I prepend something to favesQuery and blockedQuery?
Thinking in SQL terms, I'm looking for the equivalent of an WHERE 1=1 AND ...
Related question https://groups.google.com/forum/?fromgroups=#!topic/ravendb/JKTpHiFRJLc
Rethink the structuring of the LINQ methods.
var articles = RavenSession.Advanced
.LuceneQuery<Article>("AllDocs/ByTags")
.Include(x => x.Author);
if (user.FavouriteTags.Any()) {
string favesQuery = String.Join(" OR ", user.FavouriteTags.Select(x => String.Format("Tags:{0}", x)));
articles = articles.Where(favesQuery).Boost(0.5m);
}
if (user.BlockedTags.Any()) {
string blockedQuery = String.Join(" AND ", user.BlockedTags.Select(x => String.Format("-Tags:{0}", x)));
articles = articles.Where(blockedQuery);
}
articles = articles.OrderByDescending(x => x.DatePublished);
I couldn't figure out how to create IsLike query with multiple conditions.
criteria = criteria.Add(Restrictions.Like("IpAdress", "%" + request.Keyword + "%") ||
Restrictions.Like("MacAdress", "%" + request.Keyword + "%") ||
Restrictions.Like("al.SerialNumber", "%" + request.Keyword + "%"));
How to translate query above to IQueryOver format?
Thanks!
You haven't posted what your entities look like, but you could write something along these lines:
query.Where(Restrictions.Disjunction()
.Add(Restrictions.On<Type>(x => x.IpAddress).IsLike(request.Keyword))
.Add(Restrictions.On<Type>(x => x.MacAdress).IsLike(request.Keyword))
.Add(Restrictions.On<Type2>(x => x.SerialNumber).IsLike(request.Keyword)));
or you could use || operator instead of disjunction:
query.Where(
Restrictions.On<Type>(x => x.IpAddress).IsLike(request.Keyword) ||
Restrictions.On<Type>(x => x.MacAdress).IsLike(request.Keyword) ||
Restrictions.On<Type2>(x => x.SerialNumber).IsLike(request.Keyword));
Here are some similar SO question for more info:
queryover and (x like 'a' or y like 'a')
QueryOver Or with Subquery
What's wrong with this statement? An error is occurring, it is not reading the second line
(($var = array('tab.order' => 'tab.order+1');))
$db->update('tab', $form->getValues(), array('id =?' => $id));
$var = array('tab.order' => 'tab.order+1');
$var2 = array('tab.order >= ' . $form->getValue('order'));
$db->update('tab', $var, $var2);
Your problem is likely happening when Zend_Db does it's escaping of values in $var, and the value becomes
`tab.order+1`
You'll need to do
$var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
to get around this.