Questions tagged [linq-query-syntax]

Language-Integrated Query is the name for a set of technologies based on the integration of query capabilities directly into the C# language.

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. With LINQ, a query is a first-class language construct, just like classes, methods, events.

Full Overview: https://learn.microsoft.com/en-us/dotnet/csharp/linq/index

86 questions
4
votes
3 answers

Which is fast : Query Syntax vs. Loops

The following code provides two approaches that generate pairs of integers whose sum is less than 100, and they're arranged in descending order based on their distance from (0,0). //approach 1 private static IEnumerable> …
Nawaz
  • 353,942
  • 115
  • 666
  • 851
4
votes
5 answers

Linq query to get the last record

I know this is asked many times and I've searched most of the solutions online, but nothing seems to make it for me. I have a table with this structure: ID | ScheduleId | Filename | Description 1 | 10 | | .... 2 | 10 |…
Apostrofix
  • 2,140
  • 8
  • 44
  • 71
4
votes
2 answers

Linq-to-SQL, pass Expression> to select method in query syntax

Suppose, we have next code: public class Dto { public int Id; public string Name; } ... using (var db = new NorthwindDataContext()) { var q = from boss in db.Employees from grunt in db.Employees.Where(p => p.ReportsTo ==…
dmytro.s
  • 690
  • 6
  • 20
3
votes
1 answer

Linq: query syntax where operator does not understand predicates of type Expression

I have defined a specification as an object of type Expression> like this: public static Expression> IsSystemUser { get { return user => user.UserID == -1; } } This works marvellously with queries written…
David
  • 15,750
  • 22
  • 90
  • 150
3
votes
4 answers

Sitecore7 Linq to Sitecore only works with SearchResultItem but not with Custom Mapped Class

I have this very weird problem that I cannot get my head around. Perhaps someone could point out what I am doing wrong. Basically, I am just trying to search items using Linq to Sitecore. So, my classes look like ( I am using glass…
Ali Nahid
  • 867
  • 11
  • 26
3
votes
5 answers

linq Select Collection Column Dynamic

I want select Col1 or Col2 by dynamic in linq command for example var temp1= "Col1"; thank you for answer I try by ((ICollection)x.GetType().GetProperty(temp1).GetType()).Select(g =>... but get error LINQ to Entities does not…
khoshghadam
  • 89
  • 1
  • 10
2
votes
3 answers

What's the meaning of multiple from selectors in a LINQ query

I've seen multiple from clauses in a LINQ query a few times now, but have not figured out how that corresponds to a TSQL statement. var r = from p in products from d in departments from c in something select p; What does…
John
  • 3,591
  • 8
  • 44
  • 72
2
votes
2 answers

C# object sorting by group, using linq

I have a list of objects which are grouped by a particular property. I need to sort this list based on other properties, but it always needs to retain the grouping. So for example, if the list is something like: { id=1, partNumber = 100 } { id=2,…
drowned
  • 530
  • 1
  • 12
  • 31
2
votes
1 answer

LINQ query syntax with multiple statements

Can this method be rewritten using LINQ's query syntax? public IEnumerable GetAllItems() { return Tabs.SelectMany(tab => { tab.Pick(); return tab.Items; }); } I cannot figure out where to place…
YMM
  • 632
  • 1
  • 10
  • 21
2
votes
3 answers

How to join using complex expression using Linq2Sql C# Expressions

I need to implement such query: In C# Linq2Sql Statements this can be written so: var query = from f1 in Foo from f2 in Foo where f1.Id < f2.Id && f1.Value == f2.Value select f1; But I wonder how to do this using…
Dao
  • 2,784
  • 3
  • 28
  • 36
2
votes
0 answers

Convert method syntax to query syntax

Is there any way to automatically convert from linq method syntax to query syntax? E.G.: I want to automatically convert it: var aux = Directory.EnumerateDirectories(@"c:\") .Where(directory => directory.Contains("xxx")) …
Hudson Cavazin
  • 413
  • 4
  • 12
2
votes
2 answers

Values are same but names are different using linq

There is two table in one table column is FID.. FID is in table 'tblRe ' and type in db is string and in other table column is MID .. MID is in table 'tblVeh' and type in db is int both values are same but names are different . i try to adjust but…
SUPER_USER
  • 275
  • 3
  • 16
2
votes
2 answers

Join two lists using linq queries - C#

I have an assignment where I have to join two lists of the same type (Customer). They have similar entries which I have to avoid repetitions. This is my customer class: class Customer { private String _fName, _lName; private int _age,…
ThisaruG
  • 3,222
  • 7
  • 38
  • 60
2
votes
2 answers

Implicit Conversion: Nullable(Of T) => T | VB.NET LINQ Query Syntax Vs Method Syntax

The method syntax is blocking implicit conversions, but the query syntax is not. Option Strict is on. How can I force errors to appear when using the query syntax? Whole (Completely Runnable) Program: Option Strict On Module Module1 Sub Main() …
2
votes
2 answers

Convert this Linq query from query syntax to lambda expression

I'm not sure I like linq query syntax...its just not my preference. But I don't know what this query would look like using lambda expressions, can someone help? from securityRoles in user.SecurityRoles from permissions in…
KellySandwiches
  • 929
  • 9
  • 10