Search code examples
sql-serverlinqsql-to-linq-conversion

Need Equivalent LINQ Query for the following SQL Server Query


I am looking for the equivalent LINQ query for the following Query.

SELECT SUM (Cost) FROM [Vulpith_Test2].[dbo].tbl_MilestonesForOngoingSeeker]
WHERE ([Post_Title_ID] = '3251'  
and [List_Title_ID]='1180')
and (PaymentStatus='1' or PaymentStatus='3');

Solution

  •   int sumofCost =  dbContext.tbl_MilestonesForOngoingSeeker.Where(a => a.Post_Title_ID == "3251" && a.List_Title_ID == "1180" && (a.PaymentStatus == 1 || a.PaymentStatus == 3)).Sum(a => a.Cost);