本文整理汇总了C#中PredicateExpression.AddWithOr方法的典型用法代码示例。如果您正苦于以下问题:C# PredicateExpression.AddWithOr方法的具体用法?C# PredicateExpression.AddWithOr怎么用?C# PredicateExpression.AddWithOr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PredicateExpression
的用法示例。
在下文中一共展示了PredicateExpression.AddWithOr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KreirajPredicate
/// <summary>
/// Za svaki član this.rules kolekcije kreira jedan Predicate.
/// Ako je rules.Count == 0 vraća NULL
/// </summary>
/// <returns>PredicateExpression</returns>
/// <param name="entityFieldsType">Ako se filtrira artikl onda typeof(ArtiklFields)</param>
/// <param name="getEntityFieldTypeFunction">Funkcija prima string (EntityFields type name) a vraća tip. Ako se desi da se filtrira po entitetu vezanom na glavni entitet (RacunGlava.Partner) tada se koristi ova funkcija za dohvat EntityFieldsType preko refleksije.</param>
public PredicateExpression KreirajPredicate(Type entityFieldsType,
Func<string, Type> getEntityFieldTypeFunction)
{
PredicateExpression toReturn = null;
if (rules.Count() > 0)
{
toReturn = new PredicateExpression();
foreach (JqGridFilterItem item in rules)
{
Predicate predicateToAdd = JqGridFilter.KreirajPredikatIzJqGridFilterItem(entityFieldsType, item, getEntityFieldTypeFunction);
if (predicateToAdd != null)
{
if (groupOp.ToUpper() == "AND")
{
toReturn.AddWithAnd(predicateToAdd);
}
else if (groupOp.ToUpper() == "OR")
{
toReturn.AddWithOr(predicateToAdd);
}
}
}
}
return toReturn;
}
示例2: BuildPredicateTree
private static IPredicate BuildPredicateTree(Func<string, IEntityField2> fieldGetter, Func<string, List<IEntityRelation>, IEntityField2> relatedFieldGetter, FilterNode filterNode, List<IEntityRelation> inferredRelationsList)
{
if (filterNode.NodeCount > 0)
{
if (filterNode.NodeType == FilterNodeType.Root && filterNode.Nodes.Count > 0)
{
if (filterNode.NodeCount == 1)
return BuildPredicateTree(fieldGetter, relatedFieldGetter, filterNode.Nodes[0], inferredRelationsList);
var predicate = new PredicateExpression();
foreach (var childNode in filterNode.Nodes)
{
var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList);
if (newPredicate != null)
predicate.AddWithAnd(newPredicate);
}
return predicate;
}
else if (filterNode.NodeType == FilterNodeType.AndExpression ||
filterNode.NodeType == FilterNodeType.OrExpression)
{
var predicate = new PredicateExpression();
foreach (var childNode in filterNode.Nodes)
{
var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList);
if (newPredicate != null)
{
if (filterNode.NodeType == FilterNodeType.OrExpression)
predicate.AddWithOr(newPredicate);
else
predicate.AddWithAnd(newPredicate);
}
}
return predicate;
}
}
else if (filterNode.ElementCount > 0)
{
// convert elements to IPredicate
var nodePredicate = BuildPredicateFromClauseNode(fieldGetter, relatedFieldGetter, filterNode, inferredRelationsList);
if (nodePredicate != null)
return nodePredicate;
}
return null;
}
示例3: DoSearch
/// <summary>
/// Does the search using MS Full text search
/// </summary>
/// <param name="searchString">Search string.</param>
/// <param name="forumIDs">Forum Ids of forums to search into.</param>
/// <param name="orderFirstElement">Order first element setting.</param>
/// <param name="orderSecondElement">Order second element setting.</param>
/// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param>
/// <param name="userID">The userid of the calling user.</param>
/// <param name="targetToSearch">The target to search.</param>
/// <returns>
/// TypedList filled with threads matching the query.
/// </returns>
public static SearchResultTypedList DoSearch(string searchString, List<int> forumIDs, SearchResultsOrderSetting orderFirstElement,
SearchResultsOrderSetting orderSecondElement, List<int> forumsWithThreadsFromOthers, int userID, SearchTarget targetToSearch)
{
// the search utilizes full text search. It performs a CONTAINS upon the MessageText field of the Message entity.
string searchTerms = PrepareSearchTerms(searchString);
bool searchMessageText = (targetToSearch == SearchTarget.MessageText) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);
bool searchSubject = (targetToSearch == SearchTarget.ThreadSubject) || (targetToSearch == SearchTarget.MessageTextAndThreadSubject);
if(!(searchSubject || searchMessageText))
{
// no target specified, select message
searchMessageText = true;
}
PredicateExpression searchTermFilter = new PredicateExpression();
if(searchMessageText)
{
// Message contents filter
searchTermFilter.Add(new FieldCompareSetPredicate(ThreadFields.ThreadID, MessageFields.ThreadID,
SetOperator.In, new FieldFullTextSearchPredicate(MessageFields.MessageText, FullTextSearchOperator.Contains, searchTerms)));
}
if(searchSubject)
{
// Thread subject filter
if(searchMessageText)
{
searchTermFilter.AddWithOr(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
}
else
{
searchTermFilter.Add(new FieldFullTextSearchPredicate(ThreadFields.Subject, FullTextSearchOperator.Contains, searchTerms));
}
}
IPredicateExpression mainFilter = searchTermFilter
.And(ForumFields.ForumID == forumIDs)
.And(ThreadGuiHelper.CreateThreadFilter(forumsWithThreadsFromOthers, userID));
ISortExpression sorter = new SortExpression();
// add first element
sorter.Add(CreateSearchSortClause(orderFirstElement));
if(orderSecondElement != orderFirstElement)
{
sorter.Add(CreateSearchSortClause(orderSecondElement));
}
SearchResultTypedList results = new SearchResultTypedList(false);
try
{
// get the data from the db.
results.Fill(500, sorter, false, mainFilter);
}
catch
{
// probably an error with the search words / user error. Swallow for now, which will result in an empty resultset.
}
return results;
}
示例4: CreateThreadFilter
/// <summary>
/// Creates the thread filter. Filters on the threads viewable by the passed in userid, which is the caller of the method.
/// If a forum isn't in the list of forumsWithThreadsFromOthers, only the sticky threads and the threads started by userid should
/// be counted / taken into account.
/// </summary>
/// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param>
/// <param name="userID">The user ID.</param>
/// <returns>ready to use thread filter.</returns>
internal static IPredicateExpression CreateThreadFilter(List<int> forumsWithThreadsFromOthers, int userID)
{
var threadFilter = new PredicateExpression();
if((forumsWithThreadsFromOthers != null) && (forumsWithThreadsFromOthers.Count > 0))
{
PredicateExpression onlyOwnThreadsFilter = new PredicateExpression();
// accept only those threads who aren't in the forumsWithThreadsFromOthers list and which are either started by userID or sticky.
// the filter on the threads not in the forums listed in the forumsWithThreadsFromOthers
if(forumsWithThreadsFromOthers.Count == 1)
{
// optimization, specify the only value instead of the range, so we won't get a WHERE Field IN (@param) query which is slow on some
// databases, but we'll get a WHERE Field == @param
// accept all threads which are in a forum located in the forumsWithThreadsFromOthers list
threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers[0]));
onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers[0]);
}
else
{
// accept all threads which are in a forum located in the forumsWithThreadsFromOthers list
threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers));
onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers);
}
// the filter on either sticky or threads started by the calling user
onlyOwnThreadsFilter.AddWithAnd((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID));
threadFilter.AddWithOr(onlyOwnThreadsFilter);
}
else
{
// there are no forums enlisted in which the user has the right to view threads from others. So just filter on
// sticky threads or threads started by the calling user.
threadFilter.Add((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID));
}
return threadFilter;
}
示例5: DeletePolicyFromLib
private static bool DeletePolicyFromLib(int id)
{
PredicateExpression pe = new PredicateExpression(PolicyLinkFields.PolicyId == id);
PredicateExpression peOr = new PredicateExpression(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null));
peOr.AddWithOr(PolicyLinkFields.ParentId != DBNull.Value);
pe.Add(peOr);
PolicyLinkCollection plcoll = new PolicyLinkCollection();
if (plcoll.GetMulti(pe) && plcoll.Count == 0)
{
// Policy isn't referenced in any policy document.
PolicyEntity delPolicy = new PolicyEntity(id);
delPolicy.PolicyLink.DeleteMulti();
DeletePolicy(delPolicy);
return true;
}
else
return false;
}