i want convert below query sql to linq to sql
select max(id),nleadpk from `schedule` where nleadpk > 0 &&(nleadpk ==1 || nleadpk == 2) group by nleadpk
please hlep on this . thanks in advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nanhe SiddiqueRank #1,103 · 1.7K reputationPosted Apr 16, 2015, 12:19 AM EDT
http://weblogs.asp.net/hajan/linqer-a-nice-tool-for-sql-to-linq-transition
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 16, 2015, 12:44 AM EDT
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class schedule
{
public int ID { get; set; }
public int nleadpk { get; set; }
}
class Program
{
static void Main(string[] args)
{
List
objSchedule.Add(new schedule{ID= 3,nleadpk=1});
objSchedule.Add(new schedule{ID= 4,nleadpk=2});
objSchedule.Add(new schedule{ID= 5,nleadpk=2});
//Use below any query.
var linqmaxIdList = (from obj in objSchedule
where (obj.nleadpk > 0 && obj.nleadpk == 1) || (obj.nleadpk == 2)
group obj.ID by obj.nleadpk into gkey
select gkey.Max()
).ToList();
var lemdamaxIdList = objSchedule
.Where(w => (w.nleadpk > 0 && w.nleadpk == 1) || w.nleadpk == 2)
.GroupBy(g => g.nleadpk, g => g.ID, (gKey, gValue) => gValue.Max()).ToList();
foreach (var max in lemdamaxIdList)
{
Console.WriteLine(max);
}
}
}
}
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 16, 2015, 1:06 AM EDT
http://www.sqltolinq.com/
Pankil BhattRank #2,947 · 489 reputationPosted Apr 16, 2015, 1:09 AM EDT
Use the LINQPad.
Install it on your system.
https://www.linqpad.net/
Thanks