Questions tagged [linq-method-syntax]
49 questions
10
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
- 4,243
- 2
- 27
- 31
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,572
- 3
- 18
- 15
5
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
- 3,113
- 4
- 38
- 57
4
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
- 251
- 1
- 5
- 17
3
votes
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
- 75
- 2
- 9
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,595
- 15
- 37
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…
user11076564
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
1 answer
Join on Condition With Linq Methods
Say I have a class
Class Record
{
int Id
int StartDate
}
Class DBRecord
{
int Id
DateTime StartDate
DateTime EndDate
}
How could I join these using the linq methods syntax with a condition that the start date is between the…

johnny 5
- 19,893
- 50
- 121
- 195
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()
…

Vincent Saelzler
- 177
- 1
- 7
1
vote
2 answers
How to group columns by table name in LINQ Method Syntax in Table Relationships C# ASP .NET Entity Framework Core 6 Web API?
I am new at C# ASP.Net Entity Framework . I am trying to build an API and I want to produce an output like this :
[
{
"userId": 1275,
"username": "dmartin",
"email": "Dan.Martin@i-s-consulting.com",
…

Ken
- 53
- 6
1
vote
2 answers
Linq method - Return rows only found in another table
I want to return the Tags from the Tag table that are only found in the TagRecipe table. How can I do this?
var dataTags = await _context.Tags
.Include(tc => tc.TagCategory)
.ToListAsync();
public…

JAmes
- 261
- 1
- 5
- 15
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
- 366
- 4
- 19
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
- 6,094
- 4
- 49
- 81
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
- 344
- 2
- 11