Ich möchte einen dynamischen where
Zustand haben.Wie implementiere ich eine dynamische Where-Klausel in LINQ?
Im folgenden Beispiel:
var opportunites = from opp in oppDC.Opportunities
join org in oppDC.Organizations
on opp.OrganizationID equals org.OrgnizationID
where opp.Title.StartsWith(title)
select new
{
opp.OpportunityID,
opp.Title,
opp.PostedBy,
opp.Address1,
opp.CreatedDate,
org.OrganizationName
};
Einige Male habe ich Title
und manchmal mache ich nicht. Und ich möchte auch Datum in where
Klausel dynamisch hinzufügen.
Zum Beispiel, wie diese SQL:
string whereClause;
string SQL = whereClause == string.Empty ?
"Select * from someTable" : "Select * from someTable" + whereclause
Denken Sie daran, dass Sie nicht wirklich * schreiben * [T] SQL hier ... Sie schreiben C# –