Clint Davis

Application Development, Databases, and Philosophy

Tag: linq

Alias names in LINQ

Finally figured out how to set alias names in LINQ, and it’s easy. Dim orgs = From p In db.Departments Select p.deporg, Name = p.deporg & " – " & p.depname Order By deporg Name being the name of the concatenated field of p.deporg and p.depname.

LINQ: Filtering against a list

I was trying to filter a LINQ query against a hard coded list and Visual Studio kept complaining that it was wrong. I was trying to do something like this: Dim orgnums As New List(Of String) orgnums.Add("210") orgnums.Add("750")   Dim depts = From p In db.Departments Where p.deporg.Contains(orgnums) Select p.depname Turns out you need to [...]

Group in LINQ

I keep forgeting how to group by in LINQ and it’s something I do regularly. So here is my cheat sheet. Here is the original T-SQL. SELECT orgno, psno, sche, projid, RecType, Sum(OBBudExpAmt) AS OBBudExpAmt, Sum(ABBudEncAmt) AS ABBudEncAmt From tbl908_BudSPDGrps Where orgno = ’210′ GROUP BY orgno, psno, sche, projid, RecType And this is the [...]