Why my LINQ expression do not work in LINQ to SQL?
Date : March 29 2020, 07:55 AM
wish help you to fix your issue public Expression<Func<T, bool>> Combine<T>(Expression<Func<T, Boolean>> first, Expression<Func<T, Boolean>> second)
{
var toInvoke = Expression.Invoke(second, first.Parameters.Cast<Expression>());
return (Expression.Lambda<Func<T, Boolean>>(Expression.AndAlso(first.Body, toInvoke), first.Parameters));
}
|
Sortable JqGrid using LINQ to MySQL (DbLinq) and Dynamic LINQ - Orderby doesn't work
Tag : chash , By : Martin
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've got problem with sorting entries in JqGrid. Orderby seem to not work. I set breakpoint in code and I noticed, that orderby doesn't change order of elements. Any idea what could be wrong? , Try with the following public ActionResult All(string sidx, string sord, int page, int rows)
{
IQueryable<Ticket> repository = ZTRepository.GetAllTickets();
int totalRecords = repository.Count();
// first sorting the data as IQueryable<Ticket> without converting ToList()
IQueryable<Ticket> orderdData = repository;
System.Reflection.PropertyInfo propertyInfo =
typeof(Ticket).GetProperty (sidx);
if (propertyInfo != null) {
orderdData = String.Compare(sord,"desc",StringComparison.Ordinal) == 0 ?
(from x in repository
orderby propertyInfo.GetValue (x, null) descending
select x) :
(from x in repository
orderby propertyInfo.GetValue (x, null)
select x);
}
// if you use fields instead of properties, then one can modify the code above
// to the following
// System.Reflection.FieldInfo fieldInfo =
// typeof(Ticket).GetField (sidx);
// if (fieldInfo != null) {
// orderdData = String.Compare(sord,"desc",StringComparison.Ordinal) == 0 ?
// (from x in repository
// orderby fieldInfo.GetValue (x, null) descending
// select x) :
// (from x in repository
// orderby fieldInfo.GetValue (x, null)
// select x);
//}
// paging of the results
IQueryable<Ticket> pagedData = orderdData
.Skip ((page > 0? page - 1: 0) * rows)
.Take (rows);
// now the select statement with both sorting and paging is prepared
// and we can get the data
var rowdata = ( from ticket in tickets
select new {
id = ticket.ID,
cell = new String[] {
ticket.ID.ToString(), ticket.Hardware, ticket.Issue,
ticket.IssueDetails, ticket.RequestedBy,
ticket.AssignedTo, ticket.Priority.ToString(),
ticket.State
}
}).ToList();
var jsonData = new {
total = page,
records = totalRecords,
total = (totalRecords + rows - 1) / rows,
rows = pagedData
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
|
Why this Linq doesn't work (Error translating Linq expression to URI: Can only specify query options (orderby, where, ta
Tag : chash , By : Sigfrieg
Date : March 29 2020, 07:55 AM
help you fix your problem Basically, you have to condense your where clause into a single where clause after all of the navigations (from) have been performed, like so: var query =
from ch in Client.wcf.context.CashHeading
from cs in Client.wcf.context.Cash
from gg in Client.wcf.context.Good
where
ch.Id_customer == customern && //cc.Id
cs.Id_cashheading == ch.Id &&
gg.Id == cs.Id_good
select gg.Price.Value;
|
Convert an IQueryable linq query to IEnumerable<T> cancels out linq optimized way to work?
Tag : chash , By : Guy Kastenbaum
Date : March 29 2020, 07:55 AM
I hope this helps . It's still going to execute in the database, don't worry. Basically it's all down to which implementation of Where etc is used. While you're calling methods on IQueryable - via the Queryable extension methods - it will be using expression trees. When you start to fetch from that query, it will be turned into SQL and sent to the database. On the other hand, if you use any of those methods after you've got it as an IEnumerable (in terms of the compile-time type), that will use the extension methods in Enumerable, and all of the rest of the processing would be done in-process.var query = db.People
.Where(x => x.Name.StartsWith("J"))
.AsEnumerable()
.Where(x => x.Age > 20);
|
LINQ Queries work in LINQ Pad not in VS
Tag : chash , By : user140973
Date : March 29 2020, 07:55 AM
it helps some times Well, add a property Area to Shift. EF should pick it up as a 1:n (Area : Shift) relation between both classes and translate it into a SQL join. – Gert Arnold
|