Questions tagged [sql-to-linq-conversion]

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

243 questions
3
votes
1 answer

how to use group by in linq C# and fetch the list of records

i have a 2 tables and i do some joins to return a list of records based on some requirement. I am able to write a group by query for my requiremnet and fecth the records,but i need the same in Linq query. my sql query is : select …
Santosh
  • 2,355
  • 10
  • 41
  • 64
3
votes
1 answer

Convert SQL query with join to lambda expression

not sure how to convert the following sql into a lambda expression. My database uses referential integrity and table Content related to table Content_Training in a 1 to many relationship (1 content can have many content_trainings) select…
3
votes
3 answers

Checking for Nulls on DB Record Mapping

How can I check for db null values in the attached code? Please understand I am a new C# convert... What this code does is takes a IDataReader object and converts and maps it to a strongly-typed list of objects. But what I am finding is it…
Kevin
  • 2,684
  • 6
  • 35
  • 64
3
votes
1 answer

Linq expression multiple left outer join error

I am unable to execute the below linq. var items( from p in Patients join q in MURWorksheets on p.PatientId equals q.PatientId into step1 from s in step1.DefaultIfEmpty() join t in MURWorksheetAnswers on s.MURWorksheetId equals…
Khan Aamir
  • 145
  • 1
  • 18
3
votes
2 answers

Convert SQL into Linq query

I'm quite new at Linq queries, I just want to convert my DB query into Linq. Here is my simple SQL query: var query = "SELECT EnrollmentDate, COUNT(*) AS StudentCount " + "FROM Person " + "WHERE EnrollmentDate IS NOT NULL " …
Ashok Damani
  • 3,896
  • 4
  • 30
  • 48
2
votes
1 answer

C# multiple OR conditions in LINQ query

I am trying to link multiple values OR in a loop with LINQ. Situation Plattform: .net 5 C# 9 We are building a filter logic for a list. In the current case it concerns string values which are to be filtered. The user can search for one or more…
TheBigNeo
  • 129
  • 1
  • 7
2
votes
0 answers

How to rewrite the SQL Server SUM(1) in LINQ C#?

I have a SQL Server query and I rewrite this query in c# by using LINQ. In the T-SQL query, there is a sum like that: SELECT Date, Name, SUM(1) AS ItemCount, SUM(ProductCount) AS ProductCount FROM somewhere GROUP BY Date, Name I write the…
simoncare
  • 75
  • 1
  • 8
2
votes
3 answers

left join with up to one row in the right table in LINQ

Hifriends, I have one customer table and one relationship table where I keep the customers I send survey link to. The same survey may have been sent to the same customer more than once. Or, some customers may not have sent any survey links. my goal…
user6172721
2
votes
2 answers

NHibernate parent list with child count

i am using NHibernate 4 with mysql. i have got 2 tables. My tables are cat and answer. public class cat { [Key] public virtual int id { get; set; } public virtual string catName { get; set; } public virtual IList answers {…
2
votes
2 answers

Converting SQL to Linq query

I'm trying to get the output of the following query into a Linq query SELECT SearchQueries.Query, Clicks.Name, COUNT (SearchQueries.Query) AS Hits FROM SearchQueries INNER JOIN Clicks ON Clicks.SearchqueryId = SearchQueries.Id GROUP BY…
Kiwi
  • 2,713
  • 7
  • 44
  • 82
2
votes
2 answers

Why my Linqued query is not giving me proper result?

I have this sql query which gives me proper result i.e all the names of employee sorted by A to Z using order by clause select Distinct(EmpNTLogin),Employee from Attendance where CreateDate>='2016-01-01' order by EmpNTLogin when I converted the…
akash
  • 173
  • 1
  • 14
2
votes
1 answer

Converting a SQL subqueries to Linq query

I am trying to convert this sql into Linq query but I am getting no success. Could you help with the same. SELECT G.Id,G.UserGroupName, G.Status, G.IsDeleted ,(SELECT COUNT(*) FROM UserGroupMapping U WHERE U.UserGroupId=G.Id) [UserCount] …
2
votes
2 answers

Getting Column Value from another Subquery

I have a LINQ query. But I need to get value of two columns from another subquery. This is my Linq query: )from t in db.PUTAWAYs join t0 in db.ASN_ITEM on t.AWB_NO equals t0.AWB_NO join t1 in db.ASN_MASTER on t0.AWB_NO equals t1.AWB_NO join t2 in…
Limna
  • 401
  • 10
  • 28
2
votes
1 answer

Convert SQL with multiple join into LINQ

I would like to know how can i change the following sql statement into Linq or Lambda Extension in C# SELECT m.mdes as AgeGroup,COUNT(DISTINCT(mbcd))as "No.of Member" FROM mageg m LEFT JOIN (select distinct(mbcd) ,mage FROMtevtl JOIN mvipm ON…
M.A
  • 1,073
  • 2
  • 15
  • 21
2
votes
1 answer

Linq To SQL - Having and Group By

I've this query below working fine. However I want to implement it using Linq. select u.ID, u.NAME from Task t join BuildingUser bu ON bu.ID_BUILDING = t.ID_BUILDING join [User] u ON u.ID = bu.ID_USER where t.ID IN (2,9) AND u.ID !=…
gandarez
  • 2,609
  • 4
  • 34
  • 47
1
2
3
16 17