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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankil BhattPosted Apr 16, 2015, 5:09 AM
Use the LINQPad.
Install it on your system.
https://www.linqpad.net/
Thanks
Munesh SharmaPosted Apr 16, 2015, 5:06 AM
http://www.sqltolinq.com/
Abrar Ahmad AnsariPosted Apr 16, 2015, 4:44 AM
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);
}
}
}
}
Nanhe SiddiquePosted Apr 16, 2015, 4:19 AM
http://weblogs.asp.net/hajan/linqer-a-nice-tool-for-sql-to-linq-transition