Convert linq query into VB.net

Posted by Blessyjees under VB.NET on 4/11/2012 | Points: 10 | Views : 6598 | Status : [Member] | Replies : 6
Hi,

Anybody help me to convert below linq query in c# into VB.net

 var revenueByStaff = from staffRevenue in cc_response.invoices
join staffList in staff_response.staff_members
on staffRevenue.staff_id equals staffList.staff_id
select new {first_name=staffList.first_name, last_name=staffList.last_name, staff_id=staffList.staff_id, amount=Convert.ToDecimal(staffRevenue.amount), currency_code=staffRevenue.currency_code, Month=Convert.ToDateTime(staffRevenue.date).Month};

var staffByMonth = from rs in revenueByStaff
group rs by new { rs.currency_code, rs.staff_id, rs.Month,rs.first_name,rs.last_name } into grp
select new { grp.Key, amount = grp.Sum(s => s.amount) };

var sm = staffByMonth.GroupBy(a => new { a.Key.first_name, a.Key.currency_code }).Select(g =>
{
var dict = new Dictionary<string, decimal>();
foreach (var i in g)
dict.Add(i.Key.Month.ToString(), i.amount);
return new { staff = g.Key, rpt = dict };
}).Select(a=> new Invoice{Name=a.staff.first_name,Currency=a.staff.currency_code,Month=a.rpt});
List<Invoice> ui =sm.ToList<Invoice>();
rptRevenueByStaff.DataSource = ui.OrderBy(o=>o.Name);
rptRevenueByStaff.DataBind();

i can able to convert first two statements but not possible the third.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/



Responses

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
var revenueByStaff = from staffRevenue in cc_response.invoices _

join staffList in staff_response.staff_members _
on staffRevenue.staff_id equals staffList.staff_id _
select new With _
{
.first_name=staffList.first_name, _
.last_name=staffList.last_name, _
.staff_id=staffList.staff_id, _
.amount=Convert.ToDecimal(staffRevenue.amount), _
.currency_code=staffRevenue.currency_code, _
.Month=Convert.ToDateTime(staffRevenue.date).Month _
};


I have converted only one query.

Check this query is working or not......



Thanks,
Rajni Shekhar

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
How to convert friends?
i can't understand. anybody can explain to me...

Thanks & Regards
Hari

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Hari,
There are some rule to in VB.NET for LINQ.
Like if you use select new use with, for next line use space and underscore and many more. for more information use following link.

http://msdn.microsoft.com/en-us/vstudio/bb688088
http://www.aspecttraining.co.uk/outlines/LINQ_for_VB_Developers.pdf
http://www.dreamincode.net/forums/topic/62023-using-linq/

Thanks,
Rajni Shekhar

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
hi Rajini,

I can convert first 2 statement. I need to help only on third statement.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
check following link, may be help you,

http://stackoverflow.com/questions/2831830/vb-net-groupby-linq-statement

Thanks,
Rajni Shekhar

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
check below link also...
http://msdn.microsoft.com/en-us/library/bb384667.aspx

Thanks,
Rajni Shekhar

Blessyjees, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response