本文整理汇总了C#中ICriteria.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ICriteria.Add方法的具体用法?C# ICriteria.Add怎么用?C# ICriteria.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICriteria
的用法示例。
在下文中一共展示了ICriteria.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildCriteria
protected virtual ICriteria BuildCriteria(ISession session)
{
if (cachedCriteria == null)
{
if (detachedCriteria != null)
{
cachedCriteria = detachedCriteria.GetExecutableCriteria(session);
}
else
{
cachedCriteria = session.CreateCriteria(targetType);
if (criterions != null)
{
foreach (var queryCriteria in criterions)
{
cachedCriteria.Add(queryCriteria);
}
}
}
if (orders != null)
{
foreach (var order in orders)
{
cachedCriteria.AddOrder(order);
}
}
}
return cachedCriteria;
}
示例2: AppendStringPropertyCriteriaTo
private static void AppendStringPropertyCriteriaTo(
ICriteria criteria, PropertyInfo signatureProperty, object propertyValue)
{
criteria.Add(
propertyValue != null
? Restrictions.InsensitiveLike(signatureProperty.Name, propertyValue.ToString(), MatchMode.Exact)
: Restrictions.IsNull(signatureProperty.Name));
}
示例3: AppendEntityCriteriaTo
private static void AppendEntityCriteriaTo(
ICriteria criteria, PropertyInfo signatureProperty, object propertyValue)
{
criteria.Add(
propertyValue != null
? Restrictions.Eq(signatureProperty.Name + ".Id", ((IEntity)propertyValue).Id)
: Restrictions.IsNull(signatureProperty.Name + ".Id"));
}
示例4: AddExpressionToCriteria
/// <summary>
/// Adiciona uma Expressão ao ICriteria
/// </summary>
/// <param name="type">Tipo da Entidade do ICriteria</param>
/// <param name="criteria">ICriteria</param>
/// <param name="propriedade">Nome da Property do Tipo</param>
/// <param name="expressao">Expressão do ICriteria</param>
/// <param name="valor">Valor para Comparação</param>
private void AddExpressionToCriteria(Type type, ICriteria criteria, string propriedade, int expressao, object valor)
{
//Converte o valor object no tipo da Property usando Reflection a partir do Type
object value = Convert.ChangeType(valor, type.GetProperty(propriedade).PropertyType);
//Adiciona a Expression no Criteria
switch (expressao)
{
case 0:
criteria.Add(Expression.Eq(propriedade, value));
break;
case 1:
criteria.Add(Expression.Not(Expression.Eq(propriedade, value)));
break;
case 2:
criteria.Add(Expression.Gt(propriedade, value));
break;
case 3:
criteria.Add(Expression.Ge(propriedade, value));
break;
case 4:
criteria.Add(Expression.Lt(propriedade, value));
break;
case 5:
criteria.Add(Expression.Le(propriedade, value));
break;
case 6:
criteria.Add(Expression.Like(propriedade, value));
break;
}
}
示例5: AddWordRestrictions
private static void AddWordRestrictions(string query, ICriteria criteria)
{
query.Split(' ').ForEach(word => criteria.Add(
Restrictions.Or(
Restrictions.InsensitiveLike("Title", word, MatchMode.Anywhere),
Restrictions.Or(
Restrictions.InsensitiveLike("ShortDescription", word, MatchMode.Anywhere),
Restrictions.InsensitiveLike("LongDescription", word, MatchMode.Anywhere))
)));
}
示例6: AddCriterionToCriteria
/// <summary>
/// Adds a collection of ICriterion to an ICriteria.
/// </summary>
/// <param name="criteria">The ICriteria that will be modified.</param>
/// <param name="criterions">The collection of Criterion.</param>
internal static void AddCriterionToCriteria(ICriteria criteria, ICriterion[] criterions)
{
if (criterions != null)
{
foreach (ICriterion cond in criterions)
{
criteria.Add(cond);
}
}
}
示例7: SetSearchCriteria
public static ICriteria SetSearchCriteria(object obj, ICriteria c)
{
Type t = obj.GetType();
string strTemp;
foreach (PropertyInfo p in t.GetProperties())
{
if (p.GetValue(obj, null) == null) continue;
strTemp = p.GetValue(obj, null).ToString();
if (strTemp != "")
c.Add(Expression.Eq(p.Name, p.GetValue(obj, null)));
}
return c;
}
示例8: ConstructCriteria
public ICriteria ConstructCriteria(bool matchAllCriteria, ICriteria criteria, params AbstractCriterion[] criterias)
{
if (matchAllCriteria)
{
var conjunction = Restrictions.Conjunction();
foreach (var t in criterias.Where(t => t != null))
{
conjunction.Add(t);
}
criteria.Add(conjunction);
}
else
{
var disjunction = Restrictions.Disjunction();
foreach (var t in criterias.Where(t => t != null))
{
disjunction.Add(t);
}
criteria.Add(disjunction);
}
return criteria;
}
示例9: AddCommaDelimitedStringsToExpression
/// <summary>
/// Adds the comma delimited strings to the expression factory.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <param name="expressions">The expressions.</param>
/// <param name="text">The text.</param>
/// <param name="propertyName">Name of the property.</param>
/// <param name="clause">The clause.</param>
private static void AddCommaDelimitedStringsToExpression(ICriteria criteria, IExpressionFactory expressions, String text,
String propertyName, SearchParameter clause)
{
if (!string.IsNullOrEmpty(text))
{
IList<IExpression> expression = new List<IExpression>();
IJunction junction;
string[] values = text.Split(',');
foreach (String value in values)
{
expression.Add(GetExpression(expressions, clause, propertyName, value));
}
junction = expressions.Disjunction();
foreach (IExpression e in expression)
{
junction.Add(e);
}
criteria.Add(junction);
}
return;
}
示例10: GetFilterCriteria
private static void GetFilterCriteria(ICriteria cr, string keyword)
{
if (!string.IsNullOrEmpty(keyword))
cr.Add(Restrictions.InsensitiveLike("dept.Name", keyword, MatchMode.Anywhere));
}
示例11: AddTimePeriodRestrictions
private static void AddTimePeriodRestrictions(TimePeriod period, ICriteria criteria)
{
criteria
.Add(Restrictions.Eq("Year", period.Year))
.Add(Restrictions.Eq("YearRange", period.YearRange))
.Add(Restrictions.Eq("Quarter", period.Quarter))
.Add(Restrictions.Eq("Month", period.Month));
}
示例12: OnSetFilters
/// <summary>
/// Called when [set filters] event is fired on the TargetViewDataSource object.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <param name="expressions">The expressions.</param>
protected void OnSetFilters(ICriteria criteria, IExpressionFactory expressions)
{
ICampaign campaign = GetParentEntity() as ICampaign;
criteria.Add(expressions.Eq("Campaignid", campaign.Id.ToString()));
if (!chkContacts.Checked && !chkLeads.Checked)
criteria.Add(expressions.Eq("TargetType", "NONE"));
if (chkContacts.Checked && !chkLeads.Checked)
criteria.Add(expressions.Eq("TargetType", "Contact"));
if (!chkContacts.Checked && chkLeads.Checked)
criteria.Add(expressions.Eq("TargetType", "Lead"));
if (chkPriority.Checked && lbxPriority.SelectedItem != null)
criteria.Add(expressions.Eq("Priority", lbxPriority.SelectedItem.Text));
if (chkGroup.Checked && lbxGroups.SelectedItem != null)
criteria.Add(expressions.Eq("GroupName", lbxGroups.SelectedItem.Text));
if (chkStatus.Checked && lbxStatus.SelectedItem != null)
criteria.Add(expressions.Eq("Status", lbxStatus.SelectedItem.Text));
if (chkStage.Checked && lbxStages.SelectedItem != null)
criteria.Add(expressions.Eq("Stage", lbxStages.SelectedItem.Text));
if (chkResponded.Checked)
{
criteria.Add(rdgResponded.SelectedIndex == 0
? expressions.IsNotNull("ResponseDate")
: expressions.IsNull("ResponseDate"));
}
}
示例13: AddRestriction
private void AddRestriction(ICriteria criteria, String type, Object value,Boolean exactMatch)
{
if (criteria != null && type != null && value != null){
if (exactMatch){
criteria.Add(Restrictions.Eq(type, value));
} else{
criteria.Add(Restrictions.Like(type, value));
}
}
}
示例14: GetFilterCriteria
private void GetFilterCriteria(ICriteria criteria, int find, string keyword)
{
string text = string.Format("%{0}%", keyword);
// Search by make
if (find == 1)
{
ICriterion qmake = Restrictions.Like("Make", text, MatchMode.Anywhere);
criteria.Add(qmake);
}
// Search by model
else if (find == 2)
{
ICriterion qmodel = Restrictions.Like("Model", text, MatchMode.Anywhere);
criteria.Add(qmodel);
}
// Search by year
else if (find == 3)
{
try
{
int year = Convert.ToInt32(keyword);
ICriterion qyear = Restrictions.Eq("Year", year);
criteria.Add(qyear);
}
catch
{
}
}
// Search by doors
else if (find == 4)
{
try
{
int doors = Convert.ToInt32(keyword);
ICriterion qdoors = Restrictions.Eq("Doors", doors);
criteria.Add(qdoors);
}
catch
{
}
}
// Search by colour
else if (find == 5)
{
ICriterion qcolour = Restrictions.Like("Colour", text, MatchMode.Anywhere);
criteria.Add(qcolour);
}
// Search by price
else if (find == 6)
{
double price = Convert.ToDouble(keyword);
ICriterion qprice = Restrictions.Eq("Price", price);
criteria.Add(qprice);
}
// Search all
else
{
bool isNumeric = Utils.IsNumber(keyword);
if (!isNumeric)
{
ICriterion qmake = Restrictions.Like("Make", text, MatchMode.Anywhere);
ICriterion qmodel = Restrictions.Like("Model", text, MatchMode.Anywhere);
ICriterion qcolour = Restrictions.Like("Colour", text, MatchMode.Anywhere);
AbstractCriterion exp1 = Restrictions.Or(qmake, qmodel);
AbstractCriterion exp2 = Restrictions.Or(exp1, qcolour);
criteria.Add(exp2);
}
else
{
int year = Utils.GetInt(keyword);
int doors = Utils.GetInt(keyword);
double price = Utils.GetDouble(keyword);
ICriterion qyear = Restrictions.Eq("Year", year);
ICriterion qdoors = Restrictions.Eq("Doors", doors);
ICriterion qprice = Restrictions.Eq("Price", price);
ICriterion qmake = Restrictions.Like("Make", text, MatchMode.Anywhere);
ICriterion qmodel = Restrictions.Like("Model", text, MatchMode.Anywhere);
ICriterion qcolour = Restrictions.Like("Colour", text, MatchMode.Anywhere);
AbstractCriterion exp1 = Restrictions.Or(qyear, qdoors);
AbstractCriterion exp2 = Restrictions.Or(exp1, qprice);
AbstractCriterion exp3 = Restrictions.Or(exp2, qmake);
AbstractCriterion exp4 = Restrictions.Or(exp3, qmodel);
AbstractCriterion exp5 = Restrictions.Or(exp4, qcolour);
//.........这里部分代码省略.........
示例15: Apply
public override void Apply(ICriteria criteria)
{
if (PostId != 0)
{
criteria.Add(Expression.Eq("Post.Id", PostId));
}
base.Apply(criteria);
}