Group By and Sum clauses in LINQ
Date : March 29 2020, 07:55 AM
it should still fix some issue The g in your LINQ expression is an IEnumerable containing a's with an extra property Key. If you want to access fields of a that are not part of Key you will have to perform some sort of aggregation or selection. If you know that a particular field is the same for all elements in the group you can pick the value of the field from the first element in the group. In this example I assume that c has a field named Value: var rows = from a in query
group a by new {
h = a.c.BookingRefex,
b = a.c.ClientRefex,
c = a.b.PickupCity,
d = a.b.PickupPostalCode
} into g
select new {
BookingRefex = g.Key.h,
ClientRefex = g.Key.b,
SumQuantity = g.Sum(p => p.bg.Quantity),
Value = g.First().c.Value
};
|
Having 3 where clauses in LINQ
Tag : chash , By : alexmajy
Date : March 29 2020, 07:55 AM
seems to work fine I have 3 where clauses in LINQ, but its failing - I tried this , Try this. I changed the "where" with an "and" var q = (from up in UserReports
where up.UserType == "Internal"
&& companies.Contains(up.CompanyId) && roleIDs.Contains(up.RoleId)
select new
{
UserId = up.UserId,
FirstName = up.FirstName,
LastName = up.LastName, ...});
var q = (from up in UserReports
join c in companies on up.CompanyID equals c.Id
join r in rolesIDs on up.RoleId equals r.Id
where up.UserType == "Internal"
select new
{
UserId = up.UserId,..});
|
Which where clauses in LINQ are converted to where clauses in a database query
Tag : chash , By : Jenuel
Date : March 29 2020, 07:55 AM
should help you out Here is the MSDN page detailing which methods LINQ to SQL supports. You will not be able to use your own method calls inside of the expression tree, as LINQ to SQL does not understand how to convert the methods into SQL.
|
Rearranging the clauses in my LINQ?
Tag : chash , By : kiirpi
Date : March 29 2020, 07:55 AM
will be helpful for those in need My understanding is that this could work (but I missed the latest comments...): var ud = db.Updates
.Where(c => !c.Sold)
.GroupBy(c => c.Vehicle, x => x, (x,gr) => new { key = x,
list = gr.ToList().OrderByDescending(z => z.TimeStamp).First() })
.Where(x=> validStatuses.Contains(x.list.Status))
.Select(x => x.list).ToList();
|
LINQ with two From clauses
Tag : chash , By : Elwillow
Date : March 29 2020, 07:55 AM
it fixes the issue Your output2 is incorrect because you are not flattening the results of the nested Select. Use SelectMany: var output2 = thisCurrency.SelectMany(lc => otherCurrency.Select(oc => oc * lc));
|