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)="For sigtig"));
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.
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)="For
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.
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.
SQL cannot be converted to LINQ: SQL with sub join cannot be converted to LINQ??
This is getting annoying.
ASKER
There must be someone out there able to translate 5 lines of SQL code to Linq C-sharp?!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Havent tried it.
http://dotnet.dzone.com/news/linqer-%E2%80%93-nice-tool-sql-linq?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+zones%2Fcss+(CSS+Zone)