したがって、この質問に本当に答える質問はここにはありませんでした。linq に関する初心者の質問ですが、次の sql クエリ (C# を使用して作成) を linq クエリに変換できるかどうかを知りたいです。
public void DoSomeQuery(bool whereCriteria1, bool whereCriteria2)
{
string sqlQuery = "SELECT p.*";
string fromClause = " FROM person p";
string whereClause = " WHERE ";
if (whereCriteria1)
{
fromClause += ", address a";
whereClause += " p.addressid = a.addressid and a.state = 'PA' and a.zip = '16127' "
}
if (whereCriteria2)
{
fromClause += ", color c";
whereClause += " p.favoritecolorid = c.colorid and c.name = 'blue'"
}
// arbitrarily many more criteria if blocks could be here
sqlQuery += fromClause + whereClause;
// do stuff to run the query
}
それは理にかなっていますか?追加する where 句の条件を知らせる bool 変数がたくさんあります。まあ...これは醜いので、linqでそれをやりたいです。