Questions tagged [sql-to-linq-conversion]

Use this tag for questions related to the conversion of SQL statements into LINQ statements.

243 questions
2
votes
2 answers

How to translate to Linq Expression

I have the following sql command which i cant translate into linq select Distinct(fp.Parks_Id) from ParkFeaturePark fp Inner Join Parkfeatures feat on fp.ParkFeatures_Id = feat.Id Inner Join Parks p On fp.Parks_Id = p.Id where p.Id In (Select…
gerald
  • 35
  • 1
  • 5
2
votes
1 answer

How to write a Linq query equivalent to this SQL

I'm trying to figure out how to write a linq query that will return equivalent results to the sql query below. The problem I'm having has to do with the two select count queries included in the select list of the main query. I need to get counts of…
Chris
  • 21
  • 1
2
votes
2 answers

Multiple Join and Group By LINQ

I need to generate this data model (example): IList fcf = new List(); fcf.Add(new FeatureGroupFeaturesDto { FeatureGroup = new FeatureGroupDto { Id = 1, Name = "Interior" }, Features = new…
Patrick
  • 2,995
  • 14
  • 64
  • 125
2
votes
1 answer

convert sql queries to linq queries

I am very new to LINQ ,I have made alot of unsuccessful attempts to convert a SQL query to LINQ.. Please help me out with some solution.What is the exact LINQ for this .. Thanks in advance. // Just a part of the entire query select distinct…
1
vote
1 answer

LINQ: How do i select 3 different column values from 3 different tables?

I have three tables Corevalue, SubjectType and Question. I want to select CoreValue.Sname, SubjectType.Cname and Question.QuestionText, I know how it works with SQL but not LINQ any help would be appreciated. Somethng like this in SQL: SELECT …
Obsivus
  • 8,231
  • 13
  • 52
  • 97
1
vote
2 answers

Convert SQL select statement to Linq

How can I convert the following SQL select statement to Linq? SELECT u.Name FROM User u AS DDC INNER JOIN Country c ON c.UserId = u.UserId INNER JOIN ( SELECT AddressId, Address, PC, FROM AddressTbl a …
Stavros
  • 5,802
  • 13
  • 32
  • 45
1
vote
2 answers

Nested selects in LINQ expression, how to?

I don't know how to work with nested selects in LINQ. How could I convert this SQl expression to LINQ? Select i.ID, i.Impression, (Select COUNT(ImpressionsId) from DiaryImpressions where DiaryPostsId = '2' AND ImpressionsId = i.ID) as Num…
Rubia Gardini
  • 815
  • 5
  • 16
  • 30
1
vote
1 answer

Convert from SQL query to LINQ syntax with outer apply and left join

I need your help. I have one SQL query, I want to convert to LINQ syntax but I don't know outer apply and left join with multi equals. I have this SQL query : string query = @"SELECT eventv3.[Index] AS ID,eventv3.EmployeeATID, emp.LastName,…
The Duy
  • 35
  • 3
1
vote
2 answers

C# - SQL to LINQ Convertion (Select latest record by ID)

I'm trying to convert this sql statement to LINQ select tm.pr_title, tm.pr_number, tm.pr_req, tm.pr_req_owner, tm.pr_dept_req, ts.pr_hdr_name , ts.pr_id_ctgy_date, ts.pr_hdr_step from tb_pr_mst_record tm inner join tb_pr_dtl_record ts on…
1
vote
2 answers

Group By Count - Iteration Count LINQ Query

I have a table like below, Name Value A Sample1 A Sample2 A Sample3 B Sample3 B Sample1 C Sample2 C Sample3 D Sample1 If I group the table by Name to get the count, Select Name, Count(*) as count from table group by…
SharmaPattar
  • 2,472
  • 3
  • 21
  • 23
1
vote
1 answer

How to write "AND NOT" in Linq Lambda expression?

I am trying to write linq lambda exp and IDK how to convert this from sql SELECT * FROM Students s WHERE s.MathGrades > 5 AND s.FizGrades > 5 AND NOT (s.MathGrades =2 AND s.FizGrades = 2) How to write "AND NOT" in linq Lambda exp ?
Coko
  • 37
  • 4
1
vote
1 answer

Convert SQL to LINQ method expression

I have scenario in database CREATE TABLE #MyVersions ( MyVersion VARCHAR(100) NULL ) DELETE FROM #MyVersions INSERT INTO #MyVersions (MyVersion) VALUES (NULL), (''), ('10001'), ('10001_2'), ('10001_3'), ('10001_4'), …
far
  • 117
  • 1
  • 6
1
vote
1 answer

Multiple Left Join with Linq and Defaults Values

I'm trying to write a query that contains multiple left joins in linq in a c# .netcore 2.2 application. I've tried writing the query in linq but it is not properly retrieving all the rows. Query I'm trying to convert is as follows. select …
nightwolf555
  • 327
  • 1
  • 14
1
vote
1 answer

SQL to LINQ Involving Multiple GroupJoin

I have a SQL Query and would like to convert into LINQ Method Syntax (Lambda) but it seems that I am stuck at the multiple group join and it confuses me. Below is the SQL that I wanted to change into LINQ select MerchantUserId, usex.Nickname,…
1
vote
2 answers

Entity Framework Query with multiple join conditions

Edited I have tables Customers, Sites, Buildings and Addresses. Every customer has zero or more (one?) sites, every site is the site of exactly one customer, namely the site that the foreign key Site.CustomerId refers to. Similarly, every site has…
VIkas
  • 15
  • 7
1 2
3
16 17