Wie implementiere ich eine dynamische 'where'-Klausel in LINQ?
Ich möchte eine Dynamik habenwhere
Bedingung.
Im folgenden Beispiel:
<code>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 }; </code>
Manchmal habe ichTitle
und manchmal auch nicht. Und ich möchte auch Datum hinzufügenwhere
Klausel dynamisch.
Zum Beispiel wie diese SQL:
<code>string whereClause; string SQL = whereClause == string.Empty ? "Select * from someTable" : "Select * from someTable" + whereclause </code>