我想數據綁定這個查詢。奇怪的LINQ查詢錯誤
cboTypeStage.DataSource =
(
from ts in tsRepository.GetTable()
select new { IdTypeStage = Convert.ToDecimal(-1), Description = "Aucun", NomFormEval = "-" }
)
.Union
(
from ts in tsRepository.GetTable()
join o in oRepository.GetTable() on ts.IdOrthEvalFormulaire equals o.IdOrthEvalFormulaire
where (ts.IdProgramme == Convert.ToDecimal(Session["selectedProg"]))
select new { IdTypeStage = ts.IdTypeStage, Description = ts.Description, NomFormEval = ((o.Nom == null) ? "Aucun" : o.Nom) }
);
,但我似乎無法得到它的工作。我得到一個錯誤:
Unable to cast object of type 'System.Data.Linq.SqlClient.SqlNew' to type 'System.Data.Linq.SqlClient.SqlValue'
我想這個SQL查詢轉換爲LINQ
SELECT -1 AS IdTypeStage, 'Aucun' AS Description, '-' AS NomFormEval
UNION
SELECT ts.IdTypeStage AS IdTypeStage, ts.Description AS Description, ISNULL(eref.Nom, 'Aucun') AS NomFormEval FROM TypeStage AS ts
LEFT OUTER JOIN OrthEvalFormulaire AS eref ON eref.IdOrthEvalFormulaire = ts.IdEvalFormulaire
WHERE IdProgramme = @IdProgramme
上的錯誤任何想法?
謝謝。
做聯合查詢的每個部分獨立工作嗎? – Jeff 2011-05-30 14:44:53
順便說一句,你可以使用'NomFormEval = o.Nom ?? 「Aucun」# – abatishchev 2011-05-30 14:47:00
@ JeffN85:他們確實獨立工作。 – Rushino 2011-05-30 14:55:37