Questions tagged [linq-method-syntax]

49 questions
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
  • 3,113
  • 4
  • 38
  • 57
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
  • 859
  • 14
  • 45
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
  • 619
  • 9
  • 21
0
votes
0 answers

Handling NULL check and assign default if NULL in LINQ

I have below SQL query trying to convert it to LINQ: if exists(select top 1'x' from tblCallerDetails where cId = @cId and bId = @bId and pId = @pid and isnull(acId, 0) =…
0
votes
2 answers

Calling query inside query in entity framework core

I want to do something like this public string GetSiteTitleFromChangeHistory(int siteId) { var changeHistories = changeHistoryRepository.GetAll(c => c.SiteRegistryId == siteId); var value =…
Alias Varghese
  • 2,104
  • 3
  • 24
  • 52
0
votes
1 answer

How to distinct a duplicate row in EF Core 6 with method syntax?

I want to query my database where I am searching a contract id by grouping them with LcNoListId. It is possible to contains duplicate value in LcNoListId column against a contract id. At this point I need to distinct all the duplicate LcNoListId and…
0
votes
0 answers

How to write Update logic using LEFT JOIN in LINQ Method Syntax?

In my .Net application, EntityFramework 6 is used and I am writing a logic in C# to update one of the column values of the ORDERTABLE to Yes or No. In ORDERTABLE, for a Single TranID there will be one or more OrderNumber. I need to update the last…
Tech Learner
  • 1,227
  • 6
  • 24
  • 59
0
votes
1 answer

How to join two tables and group by ID and count in LINQ C# method syntax

I have two tables: PractitionerSkill { Id, Title } PractitionerInSkills { Id, PractitionerSkillId ), where PractitionerSkillId is FK into PractitionerSkill (there are more columns but that is not really important) And I'm trying to count number of…
0
votes
1 answer

How to Order Data Query in Entity Framework Table Relationships LINQ Method syntax?

I am having a problem ordering data by table Iscinstances row Name in table relationships, the Iscinstances table is JOIN in LinkUsersToIscinstances table, below is my query for the table relationships. The problem is that OrderBy…
Ken
  • 53
  • 6
0
votes
1 answer

Get LINQ query Result with column value based on DateTime column

I have a table of machine details with one DateTime column in which I am entering the date and time of detail received for the corresponding machine. Sample data is like this MachineID X Y Z HealthRcvd M1 X1 Y1 Z1 2022-04-04…
Shubhit304
  • 181
  • 1
  • 15
0
votes
1 answer

Entity Framework Core JOIN with method syntax

I have a simple db structure as follows Order OrderId OrderItem OrderItemId | OrderId | BookId | OrderItemTypeId Book BookId | AuthorId I'd like to select a specific Order and all data associated with it's OrderItems plus the Author of the Book…
Fred2020
  • 315
  • 3
  • 14
0
votes
1 answer

I need to do a query on a returned list of users from another query, by Id

Currently, I have a service that grabs user information from the User table. The users can be created by admins or an employee and all of these employees have their own Id. So with that in mind, there is a column called CreatedBy which holds the id…
0
votes
3 answers

Querying a Single Item in a List

Problem I want to show a single pet on my details page. I'm having trouble understanding how to write LINQ(Method Syntax) to pull a single pet/item from the database. My understanding so far When working with LINQ, it's shining purpose is to be able…
0
votes
2 answers

How to retrieve multiple column values with same foreign key id using Linq method Syntax in C#?

This works: var query = (from user in _context.Users join role in _context.UserRoles on user.UserID equals role.UserId where user.Username == username select role.Role).ToArray(); How do I do the same in the…
Madhukar
  • 3
  • 1
0
votes
0 answers

Entity Framework Linq join method syntax

I have the following query which works fine var aaa = from d in _context.SubCategories join x in _context.CategoryLinks on d.ID equals x.SubCategoryID where x.CategoryID == CategoryID select new { …
Rick
  • 109
  • 13