-2

I need this this sql query in c# :

Select cv.manv, cv.luong1h*ct.sogiolam
From congviec cv 
inner join chitiet ct on cv.manv=ct.manv

How can I do it with LINQ to sql?

Prashanth Benny
  • 1,523
  • 21
  • 33
SeeWICDo
  • 3
  • 3

2 Answers2

0
from cv in congviec
join ct in chitiet on cv.manv equals ct.manv
select new { cv.manv, cv.luong1h*ct.sogiolam}

sorry my bad, see this edit for working solution

var list = (from cv in congviec
    join ct in chitiet on cv.manv equals ct.manv
    select new { cv.manv, Multiply = cv.luong1h*ct.sogiolam}).toList();
Abhinav
  • 1,202
  • 1
  • 8
  • 12
  • thank for your answer but it give a error Error for cv.luong1h*ct.sogiolam: Anonymous type members must be declared with a member assignment, simple name or member access. – SeeWICDo Mar 18 '17 at 13:44
  • glad to help :) .toList() is required if you are returning more than 1 items. else you can have firstordefault() or remove as you did. :) – Abhinav Mar 18 '17 at 15:02
  • yead. Tks for help !! I don't know where you are but in my country it is 22h14' good night!! – SeeWICDo Mar 18 '17 at 15:14
0

It would look almost the same in Linq

var ExampleVariable = (from cv in congviec 
                         inner join ct chitiet
                         on cv.manv equals ct.manv
                         select new { 
                                cv.manv,
                                //cv.luong1h*ct.sogiolam
                                Product =  cv.luong1h*ct.sogiolam
                                }).ToList();

And using lambda expression, refer this link.

Hope this helps.

Community
  • 1
  • 1
Prashanth Benny
  • 1,523
  • 21
  • 33