如何添加多個And和Or在Where子句中如何在Predicate Descriptionabar的where子句中添加多個Or和And Operations。 ex。如何使用Ideablade謂詞描述
List <PredicateDescription> pdList = new List<PredicateDescription>();
Dictionary< int, List< PredicateDescription>> pdDateList = new Dictionary< int, List< PredicateDescription>>();
var pds = pdList.ToArray();
if (((pds.Length > 0) || (pdDateList.Count > 0)))
{
CompositePredicateDescription predicate = null;
if (pds.Length > 0)
{
predicate = PredicateBuilder.And(pds);
}
List<PredicateDescription> AndList = null;
CompositePredicateDescription compositePredicateDescription = null;
for (int i = 0; i < pdDateList.Count; i++)
{
List<PredicateDescription> pdlist1 = pdDateList[i];
AndList = new List<PredicateDescription>();
foreach (PredicateDescription pdesc in pdlist1)
{
AndList.Add(pdesc);
}
if (AndList.Count > 0)
{
if (predicate != null)
{
if (AndList.Count == 2)
{
predicate.Or(AndList[0].And(AndList[1]));
}
else if (AndList.Count == 1)
{
predicate.Or(AndList[0]);
}
}
}
}
}
if (predicate == null)
{
predicate = compositePredicateDescription;
}
var filterQuery = query.Where(predicate);
data = Globals.sLDManager.ExecuteQuery(filterQuery);
正如上面我曾試圖在CompositePredicateDescription
添加或運營商,但它不工作
我想下面的查詢運行 -
Select * from Tabel1 where t.field1=1 and t.field2=1 and t.field3=1 Or (t.field4=1 and t.field5=1) Or (t.field6=1 and t.field7=1)
如何運行上面的查詢使用ideablade。
感謝您的回覆..我也執行了上述相同的代碼。這個對我有用。 – user1782872 2013-03-22 12:30:17