0

I have this query in SQL, and I want it to implement it in LINQ (Two tables, Caratulas, Interprete with many-to-many relation, Discos) SQL:

SELECT
Caratulas.Color, Caratulas.Forma, Caratulas.Tamano,Caratulas.Tipo
FROM
((Caratulas LEFT OUTER JOIN Discos ON Caratulas.Tipo = Discos.Tipo) 
LEFT OUTER JOIN Interprete ON Discos.EtiquetaextSoporte = Interprete.EtiquetaextSoporte)
WHERE  (Interprete.EtiquetaextSoporte = ?)

LINQ:

var FillCaratulasDesdeInterprete = caratulas.Rows.Cast<DataRow>()
.Join(Discos.Rows.Cast<DataRow>().Join(Interprete.Rows.Cast<DataRow>(),
                    rowSV => rowSV["EtiquetaextSoporte"],
                    rowS => rowS["EtiquetaextSoporte"],
                    rowSV => rowSV)
.Where(x => x["EtiquetaextSoporte"] == cadenaDesdeInterprete).DefaultIfEmpty(),
                    codV => codV["Tipo"],
                    codSV => codSV["Tipo"],
                    codV => codV)
.Where(z => z["Tipo"] == rowSV["Tipo"]).DefaultIfEmpty();

cadenaDesdeInterprete: param

but I have an error:

 Error type arguments for method
'System.Linq.Enumerable.Join<TOuter,TInner,TKey,TResult>(System.Collections.Generic.IEnumerable<TOuter>, System.Collections.Generic.IEnumerable <TInner>, System.Func <Touter, TKey>, System.Func <TInner, TKey>, System.Func <Touter, TInner, TResult>) 'they can not be inferred from the use. Try specifying the type arguments explicitly.

I thought my errors are "rowSV => rowSV", and "codV => codV" Thanks for your help.

Alicia
  • 1
  • Not an answer but...I don't really get the whole "I want to turn this SQL to LINQ". You should probably ask yourself why? Are you doing this because LINQ provides an advantage over SQL? If not and you simply want to use LINQ *because shiny* just create a Stored Procedure and call it. – Liam May 31 '16 at 16:01
  • A stored procedure would probably execute faster too. – Drew Kennedy May 31 '16 at 16:02
  • Note: `.Rows.Cast()` can be shortened to `.AsEnumerable()`. – Heinzi May 31 '16 at 16:05
  • I have read the question "LEFT OUTER JOIN in LINQ" and because of that I did my code, but I don't understand my error. A stored procedure oblige me to update the database. DataTable.Rows is a DataRowCollection without the type, DataRow, then it is not enumerable, because this method is older. Cast() introduce the type. – Alicia Jun 01 '16 at 10:59
  • List listCaratulas = (from Interprete in Discos.Rows.Cast() .Where(disco => disco.RowState != DataRowState.Deleted && Interprete["EtiquetaextSoporte"].Equals(param)) from caratula in Caratulas.Rows.Cast() .Where(caratula => caratula.RowState != DataRowState.Deleted && caratula["Tipo"].Equals(Interprete["Tipo"])) .DefaultIfEmpty() // <== makes join left join select caratula["Tipo"].ToString()).ToList(); – Alicia Jun 13 '16 at 11:16

0 Answers0