我想將一個sql請求轉換爲lambda表達式,但我只知道如何使用where語句來完成此操作。這是我的要求:將SQL resquest轉換爲C#lambda表達式
SELECT Projet.ProjetId, Projet.Libelle, UtilisateurInProjet.UtilisateurId
FROM Projet INNER JOIN
UtilisateurInProjet ON Projet.ProjetId = UtilisateurInProjet.ProjetId
WHERE (UtilisateurInProjet.UtilisateurId = @UtilisateurId)
和@UtilisateurId將成爲視圖中DropDownList的選定值。
以我控制器,I有這樣的代碼:
public JsonResult GetProjsName(int id)
{
db.Configuration.ProxyCreationEnabled = false;
List<Projet> liprojs = db.Projets.Where(x => x.ProjetId == id).ToList();
return Json(liprojs, JsonRequestBehavior.AllowGet);
}
和 「id」 爲從在視圖中的DropDownList選定的值。 謝謝
你的代碼看起來像你正在使用EntityFramework ...是你的ORM? – DarkSquirrel42
請參閱msdn:https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b – jdweng
[C#連接/ Linq和Lambda位置]的可能重複(https://stackoverflow.com/questions/2767709/ c-sharp-joins-where-with-linq-and-lambda) – Serg