Link to home
Start Free TrialLog in
Avatar of Hans_Christian
Hans_Christian

asked on

How do I transfer this code from SQL to Linq in C sharp?

I have really tried hard to get it working but I cant find the correct way to implement it in c sharp by using Linq.


SQL-Code:

SELECT Aktie.Papirnavn, Portfolio.Antal, Dagskurs.Dagskurs, Sum([Antal]*[Dagskurs]) AS Værdi
FROM (Aktie INNER JOIN Portfolio ON Aktie.Fondskode = Portfolio.Fondskode) INNER JOIN Dagskurs ON Portfolio.Fondskode = Dagskurs.Fondskode
GROUP BY Aktie.Papirnavn, Portfolio.Antal, Dagskurs.Dagskurs, Portfolio.PortfID
HAVING (((Portfolio.PortfID)="Forsigtig"));

I tried to implement some but when I try to "translate" from the pieces I read on different sites I just get tons of errors I cant understand. I got this working in a buttonclick:


            DataClasses1DataContext xxx = new DataClasses1DataContext();
            var pa = from Aktie in xxx.Akties
            join Portfolio in xxx.Portfolios on Aktie.Fondskode equals Portfolio.Fondskode
            select new {Aktie.Papirnavn, Portfolio.Antal};

            dataGridView1.DataSource = pa;



But when I try to get it more advanced i get stuck.
Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

Avatar of Hans_Christian
Hans_Christian

ASKER

Thanks for your suggestion. However  that didnt work. Program says:

SQL cannot be converted to LINQ: SQL with sub join cannot be converted to LINQ??

This is getting annoying.
There must be someone out there able to translate 5 lines of SQL code to Linq C-sharp?!
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Havent tried it.