Questions tagged [linq-method-syntax]

38 questions
9
votes
1 answer

LINQ - Method vs Query Syntax Difference

I was working with a DataTable and noticed that Resharper recommended that I can convert a loop into a LINQ expression. I did so and it was rewritten in query expression syntax (simplified): var test1 = from DataRow row in dt.Rows select…
Lester
  • 3,973
  • 2
  • 24
  • 28
6
votes
1 answer

Resharper 9 Convert to LINQ: method syntax

I've been using Resharper (c#) for many years and found the automatic convert-to-linq-expression feature extremely helpful. I've recently upgraded to V9 of resharper and it is now using linq query syntax rather than the method syntax which is my…
Andrew Thomson
  • 4,000
  • 3
  • 15
  • 15
4
votes
3 answers

LINQ Method Syntax with INNER and OUTER Join

I have 3 classes and trying to use LINQ methods to perform an INNER JOIN and a LEFT JOIN. I'm able to perform each separately, but no luck together since I can't even figure out the syntax. Ultimately, the SQL I'd write would be: SELECT * FROM…
RoLYroLLs
  • 2,775
  • 4
  • 30
  • 50
3
votes
1 answer

LINQ to Entities does not recognize my method

I want to convert date and time to Persian in LINQ select but linq can not recognize my method : LINQ to Entities does not recognize the method 'System.String toPersianDateTime(System.DateTime)' method, and this method cannot be translated into a…
Younes Jafari
  • 231
  • 1
  • 5
  • 15
3
votes
1 answer

Multiple Join Statements with LEFT JOIN to LINQ Expression syntax

I have a slightly complicated SQL query that I'm trying to convert to LINQ Expression syntax as that is what we use for our code base. Everyone online seems to use query syntax though, which is making finding the right answer quite difficult. The…
Trent
  • 1,590
  • 13
  • 36
2
votes
2 answers

Entity Framework Method Syntax Naming Convention

What are some naming conventions utilized for Entity Framework queries? Example, following code utilizes 'e. Why do they use e? And what are naming convention strategies for delegate abbreviation in method syntax? This question is not asking for…
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
  • 313
  • 3
  • 12
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() …
1
vote
3 answers

C# LINQ, dynamic grouping by [Key] attributes

Consider the following classes: public class Potato { [Key] public string Farm { get; set; } [Key] public int Size { get; set; } public string Trademark { get; set; } } public class Haybell { [Key] public string color {…
Nick Farsi
  • 164
  • 1
  • 8
1
vote
2 answers

GroupBy in List of items using LINQ

I have a list that contains item like below: Now I want to group according to language index (Languages[x]) like below: Group-1: model.Languages[0].Employer model.Languages[0].Title Group-2: model.Languages[1].Employer model.Languages[1].Title Can…
Arif
  • 4,274
  • 3
  • 40
  • 64
1
vote
1 answer

Vb.net LINQ Syntax Group By Multiple Columns using Method Syntax

I have a LINQ expression that looks something like this Dim DataRowDueTo = From row In DataTableDueTo.AsEnumerable Where row.Field(Of UInt32)("Transaction") = 1 And {"A", "B", "C"}.Contains(row.Field(Of String)("Module")) …
Ryan Tan
  • 320
  • 1
  • 10
1
vote
1 answer

LINQ Method Syntax to INCLUDE 4 Levels Deep

I have been searching without success (or not knowing how to search for this properly) so I come to you. Check out these test classes: public class A { int Id; ICollection Bs; } public class B { int Id; int AId; ICollection
RoLYroLLs
  • 2,775
  • 4
  • 30
  • 50
1
vote
4 answers

Compare 2 Lists of numbers in LINQ Method Syntax

I have 2 lists of numbers. public int[] numbersA = { 0, 2, 4 }; public int[] numbersB = { 1, 3, 5 }; I need output like below Expected Result 0 is less than 1 0 is less than 3 0 is less than 5 2 is less than 3 2 is less than 5 4 is less than…
PavanKumar GVVS
  • 441
  • 6
  • 20
1
vote
1 answer

Translate from lambda (method) syntax to query syntax (LINQ)

how it's possible to translate var vehiclequery = db.position .GroupBy(c => c.device_id) .Select(g => g.OrderByDescending(c => c.sendtime).FirstOrDefault()) .Select(c => new myPosition() …
Tunerx
  • 599
  • 7
  • 18
1
vote
3 answers

LINQ group by date - include empty days WITHOUT using join

Using C#, NHibernate, NHibernate to LINQ. Using NHibernate to LINQ, I do not have the JOIN functionality. I can not use QueryOver either. I have a LINQ query that counts the amount of Leads and Sales. This table only creates when a new lead or sale…
user2107630
  • 55
  • 1
  • 9
1
2 3