public IList BookingSearch(ICriterion criterion, string customer, int blocked, int pageSize, int pageIndex, Order order) { ICriteria criteria = _session.OpenSession().CreateCriteria(typeof(Booking), "booking"); if (criterion != null) { criteria.Add(criterion); } criteria.CreateAlias("Trip", "trip"); if (!string.IsNullOrEmpty(customer)) { DetachedCriteria detached = DetachedCriteria.For(typeof(Booking)) .CreateAlias("Customers", "customer") .SetProjection(Projections.ProjectionList() .Add(Projections.RowCount())) .Add(Property.ForName("Id").EqProperty("booking.Id")) .Add(Expression.Like("customer.Fullname", customer, MatchMode.Anywhere)); criteria.CreateAlias("Agency", "agent", JoinType.LeftOuterJoin); ICriterion crit2 = Expression.Like("agent.Name", customer, MatchMode.Anywhere); criteria.Add(Expression.Or(Subqueries.Le(1, detached), crit2)); } if (blocked > 0) { // Như vậy, bản thân booking đó không được là charter criteria.Add(Expression.Eq("IsCharter", false)); DetachedCriteria detached = DetachedCriteria.For(typeof(Booking)) .SetProjection(Projections.ProjectionList() .Add(Projections.RowCount())) .Add(Property.ForName("StartDate").GeProperty("booking.StartDate")) .Add(Property.ForName("StartDate").LtProperty("booking.EndDate")) .Add(Property.ForName("EndDate").GtProperty("booking.StartDate")) .Add(Property.ForName("EndDate").LeProperty("booking.EndDate")) .Add(Property.ForName("Cruise").EqProperty("booking.Cruise")) .Add(Expression.Eq("IsCharter", true)) .Add(Expression.Eq("Status", StatusType.Approved)); // Nếu trong khoảng trùng ngày có một booking charter đã approved criteria.Add(Subqueries.Le(1, detached)); } if (order != null) { criteria.AddOrder(order); } if (pageSize > 0) { if (pageIndex < 0) { pageIndex = 0; } criteria.SetMaxResults(pageSize); criteria.SetFirstResult(pageIndex * pageSize); } return(criteria.List()); }
public static IList <Person> FindLikeByName(Context context, bool isFirstName, String likeCustomerName) { ICriteria criteria = context.PersistenceSession.CreateCriteria <Person>(); criteria.CreateAlias("CurrentName", "pname"); if (isFirstName) { criteria.CreateAlias("pname.FirstName", "firstName") .CreateAlias("firstName.Values", "vls") .Add(Expression.Like("vls.Value", likeCustomerName, MatchMode.Start)); } IList <Person> people = criteria.List <Person>(); SetLanguage(context, people); return(people); //String languageCode = context.CurrentLanguage.Code; //String query; //if (isFirstName) // query = String.Format(QueryLikeFirstName, languageCode, likeCustomerName); //else // query = String.Format(QueryLikeLastName, languageCode, likeCustomerName); //return context.PersistenceSession // .CreateSQLQuery(query) // .AddEntity("person", typeof(Person)) // .List<Person>(); }
public override void AppendCriteria(ICriteria criteria) { criteria.CreateAlias("Title", "ProductTitle"); criteria.CreateAlias("ProductTitle.Category", "Category"); criteria.CreateAlias("ProductTitle.Brand", "Brand"); criteria.CreateAlias("ProductTitle.Color", "Color"); }
public IList <T> ObterComLeft <T>(string firstEntity, string SecondName, string type) { ICriteria criteria = Session.GetSession().CreateCriteria(type); criteria.CreateAlias(firstEntity, "entity1", JoinType.LeftOuterJoin); // inner join by default criteria.CreateAlias(SecondName, "entity2"); criteria.Add(Restrictions.IsNull(Projections.Property <T>(a => a))); return(criteria.List <T>()); }
public void Bug() { using (var session = OpenSession()) { ICriteria criteria = session.CreateCriteria(typeof(Entity1)); criteria.CreateAlias("Entities2", "ent2", JoinType.InnerJoin); criteria.CreateAlias("ent2.Id.Entity3", "ent3", JoinType.InnerJoin); criteria.CreateAlias("ent3.Entity4", "ent4", JoinType.InnerJoin); criteria.Add(Restrictions.Eq("ent4.Id", Guid.NewGuid())); Assert.DoesNotThrow(() => criteria.List <Entity1>()); } }
public override void AppendCriteria(ICriteria criteria) { // Need to create some Alias's here because Nhibernate wouldn't be able to resolve "Category.Id" or "Brand.Id" // as a query from the Product enity as NHibernate will assume that you're referring to an explicit property name and is unclear as to how the object model should be traversed. // Using CreateAlias lets NHibernate know how to resolve the relationship, this way when we are buidling a query in the service we can happily refer to // the Product properties criteria.CreateAlias("Title", "ProductTitle"); criteria.CreateAlias("ProductTitle.Category", "Category"); criteria.CreateAlias("ProductTitle.Brand", "Brand"); criteria.CreateAlias("ProductTitle.Colour", "Colour"); }
public IList PermissionsGetByUserRole(ModuleType module, User user) { ICriteria criteria = _sessionManager.OpenSession().CreateCriteria(typeof(SpecialPermission)); criteria.CreateAlias("Role", "role"); criteria.CreateAlias("role.Users", "user"); ICriterion criterion = Expression.And(Expression.Eq("user.Id", user.Id), Expression.Eq("ModuleType", module)); criteria.Add(criterion); criteria.SetProjection(Projections.Distinct(Projections.Property("Name"))); return(criteria.List()); }
public static ICriteria TranslateIntoNHQuery <T>(this Query query, ICriteria criteria) { BuildQueryFrom(query, criteria); if (query.JoinParameters != null) { foreach (Cams.Common.Querying.JoinParameters joinParameters in query.JoinParameters) { BuildJoinCriteria(joinParameters.AssociationPath, joinParameters.Alias, (NHibernate.SqlCommand.JoinType)joinParameters.JoinType, joinParameters.Criteria, joinParameters.WithClauseOperator, criteria); } } if (query.Alias != null) { foreach (Cams.Common.Querying.Alias alias in query.Alias) { criteria.CreateAlias(alias.AliasFor, alias.AliasName, (NHibernate.SqlCommand.JoinType)alias.JoinType); } } if (query.OrderByFields != null) { foreach (Cams.Common.Querying.OrderByClause orderBy in query.OrderByFields) { criteria.AddOrder(new Order(orderBy.PropertyName, !orderBy.Desc)); } } return(criteria); }
/// <summary> /// Create alias for searching by criteria /// </summary> /// <param name="criteria"></param> /// <param name="propertyName"></param> /// <returns></returns> private string CreateCriteriaAlias(IList <string> completedAliases, ICriteria criteria, string propertyName) { string aliasName = ""; string pathName = ""; string[] propertyNames = propertyName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (propertyNames.Length <= 1) { return(propertyName); } for (int i = 0; i < propertyNames.Length - 1; i++) { if (i > 0) { pathName = aliasName + "." + propertyNames[i]; aliasName = aliasName + propertyNames[i]; } else { pathName = propertyNames[i]; aliasName = propertyNames[i]; } if (!completedAliases.Contains(aliasName)) { criteria = criteria.CreateAlias(pathName, aliasName, NHibernate.SqlCommand.JoinType.LeftOuterJoin); completedAliases.Add(aliasName); } } return(aliasName + "." + propertyNames[propertyNames.Length - 1]); }
public IList <OrgDto> Search(OrgSearchRequest searchRequest, int offset, int maxEntries) { ICriteria criteria = CreateSearchCriteria(searchRequest); criteria.CreateAlias("Agency", "Agency") .SetProjection(Projections.ProjectionList() .Add(Projections.Property("LongDesc"), "LongDesc") .Add(Projections.Property("Code"), "Code") .Add(Projections.Property("Id"), "Id") .Add(Projections.Property("Agency.Id"), "AgencyId") .Add(Projections.Property("Agency.Code"), "AgencyCode") .Add(Projections.Property("Agency.LongDesc"), "AgencyLongDesc") .Add(Projections.Property("Agency.ShortDesc"), "AgencyShortDesc")); criteria.SetResultTransformer(Transformers.AliasToBean(typeof(OrgDto))); criteria.SetMaxResults(maxEntries).SetFirstResult(offset); if (!String.IsNullOrEmpty(searchRequest.SortColumn)) { if (searchRequest.SortOrder.StartsWith("A")) { criteria.AddOrder(Order.Asc(searchRequest.SortColumn)); } else { criteria.AddOrder(Order.Desc(searchRequest.SortColumn)); } } return(criteria.List <OrgDto>()); }
public IList <Models.BackupedFile> GetCompletedByStorageAccountAndPath(Models.StorageAccount account, string path, string version = null, bool ignoreCase = false) { Assert.IsNotNull(account); Assert.That(path, Is.Not.Null.Or.Empty); ICriteria crit = Session.CreateCriteria(PersistentType); string storageAccountPropertyName = this.GetPropertyName((Models.BackupedFile x) => x.StorageAccount); crit.Add(Restrictions.Eq(storageAccountPropertyName, account)); string transferStatusPropertyName = this.GetPropertyName((Models.BackupedFile x) => x.TransferStatus); crit.Add(Restrictions.Eq(transferStatusPropertyName, TransferStatus.COMPLETED)); if (version != null) { DateTime fileLastWrittenAt = DateTime.ParseExact(version, Models.BackupedFile.VersionFormat, CultureInfo.InvariantCulture); string fileLastWrittenAtPropertyName = this.GetPropertyName((Models.BackupedFile x) => x.FileLastWrittenAt); crit.Add(Restrictions.Eq(fileLastWrittenAtPropertyName, fileLastWrittenAt)); } string filePropertyName = this.GetPropertyName((Models.BackupedFile x) => x.File); string filePathPropertyName = this.GetPropertyName((Models.BackupPlanFile x) => x.Path); crit.CreateAlias(filePropertyName, "f"); SimpleExpression expr = Restrictions.Eq("f." + filePathPropertyName, path); if (ignoreCase) { expr = expr.IgnoreCase(); } crit.Add(expr); return(crit.List <Models.BackupedFile>()); }
public IList <SupportTeamDto> Search(SupportTeamSearchRequest searchRequest, int offset, int maxEntries) { ICriteria criteria = CreateSearchCriteria(searchRequest); criteria .CreateAlias("Supervisor", "Supervisor", JoinType.LeftOuterJoin) .SetProjection(Projections.ProjectionList() .Add(Projections.Property("Id"), "Id") .Add(Projections.Property("TeamName"), "TeamName") .Add(Projections.Property("PhoneNumber"), "PhoneNumber") .Add(Projections.Property("Supervisor.FirstName"), "SupervisorFirstName") .Add(Projections.Property("Supervisor.LastName"), "SupervisorLastName") //.Add(Projections.Property("SupervisorId"), "SupervisorId"); ); criteria.SetResultTransformer(Transformers.AliasToBean(typeof(SupportTeamDto))); criteria.SetMaxResults(maxEntries).SetFirstResult(offset); if (!string.IsNullOrEmpty(searchRequest.SortColumn)) { criteria.AddOrder(searchRequest.SortOrder.StartsWith("A") ? Order.Asc(searchRequest.SortColumn) : Order.Desc(searchRequest.SortColumn)); } return(criteria.List <SupportTeamDto>()); }
private IList <IProcess> GetProcessList() { IRepository <IProcess> cRep = EntityFactory.GetRepository <IProcess>(); IExpressionFactory ep = ((IQueryable)cRep).GetExpressionFactory(); ICriteria crit = ((IQueryable)cRep).CreateCriteria(); // limit the number of Processes a user can see by joining to Contact table. crit = crit.CreateAlias("Contact", "C"); // build criteria based on currently selected tab switch (ID) { case "Starting": crit = crit.Add(ep.And(ep.Eq("Suspended", 0), ep.Eq("Status", 2))); break; case "InProcess": crit = crit.Add(ep.And(ep.Eq("Suspended", 0), ep.Eq("Status", 1))); break; case "Suspended": crit = crit.Add(ep.Eq("Suspended", 1)); break; case "Waiting": crit = crit.Add(ep.And(ep.Eq("Suspended", 0), ep.Eq("Status", -2))); break; case "Completed": crit = crit.Add(ep.And(ep.Eq("Suspended", 0), ep.Eq("Status", -100))); break; case "Aborted": crit = crit.Add(ep.Eq("Status", -101)); break; } if (SlxGridView1.CurrentSortExpression == "LFName") { crit.AddOrder(SlxGridView1.CurrentSortDirection == "Ascending" ? ep.Asc("C.LastName") : ep.Desc("C.LastName")); crit.AddOrder(SlxGridView1.CurrentSortDirection == "Ascending" ? ep.Asc("C.FirstName") : ep.Desc("C.FirstName")); } else { if (SlxGridView1.CurrentSortExpression.Length > 0 && // is expression specified? SlxGridView1.CurrentSortExpression != "C.S.") // no sorting on ChangeStatus column { crit.AddOrder(SlxGridView1.CurrentSortDirection == "Ascending" ? ep.Asc(SlxGridView1.CurrentSortExpression) : ep.Desc(SlxGridView1.CurrentSortExpression)); } } try { return(crit.List <IProcess>()); } catch { return(null); } }
public void OnEvent(ICriteria crit) { switch (methodSig) { case MethodSig.AssocPathAndAlias: crit.CreateAlias(associationPath, alias); break; case MethodSig.AssocPathAndAliasAndJoinType: crit.CreateAlias(associationPath, alias, joinType); break; default: throw new ShardedSessionException("Unknown ctor type in CreateAliasEvent: " + methodSig); } }
public IList ExpenseServiceGet(SailsTrip trip, DateTime?from, DateTime?to, Agency agency, int pageSize, int pageIndex, out int count, string orgid, User user, bool hideZero, string paymentStatus, int tripType, string tripcode, params CostType[] type) { ICriteria criteria = _session.OpenSession().CreateCriteria(typeof(ExpenseService)); criteria.CreateAlias("Expense", "expense"); criteria.CreateAlias("expense.Trip", "trip"); if (tripType == 1) { criteria.Add(Expression.Not(Expression.Eq("trip.TripCode", "HUESF"))); } if (tripType == 2) { criteria.Add(Expression.Eq("trip.TripCode", "HUESF")); } if (tripcode != "") { criteria.Add(Expression.Like("trip.TripCode", tripcode, MatchMode.Anywhere)); } SetCriteriaForExpenseGet(trip, @from, to, agency, type, criteria, orgid, user, hideZero, paymentStatus); criteria.AddOrder(Order.Asc("expense.Date")); if (pageIndex < 0) { pageIndex = 0; } if (pageSize > 0) { criteria.SetMaxResults(pageSize); criteria.SetFirstResult(pageSize * pageIndex); } IList list = criteria.List(); criteria = _session.OpenSession().CreateCriteria(typeof(ExpenseService)); criteria.CreateAlias("Expense", "expense"); criteria.CreateAlias("expense.Trip", "trip"); SetCriteriaForExpenseGet(trip, @from, to, agency, type, criteria, orgid, user, hideZero, paymentStatus); criteria.SetProjection(Projections.RowCount()); IList cl = criteria.List(); count = (int)cl[0]; return(list); }
public int ExpenseServiceCount(ICriterion criterion) { ICriteria criteria = _session.OpenSession().CreateCriteria(typeof(ExpenseService)); criteria.CreateAlias("Expense", "expense"); criteria.CreateAlias("expense.Trip", "trip"); if (criterion != null) { criteria.Add(criterion); } criteria.SetProjection(Projections.RowCount()); IList cl = criteria.List(); return((int)cl[0]); }
public static TreeListNode FindByCode(Context context, String rootCode, String parentCode, String code) { ICriteria crit = context.PersistenceSession.CreateCriteria(typeof(TreeListNode)); crit.Add(Expression.Eq("Code", code)); if (!String.IsNullOrEmpty(rootCode)) { crit.CreateAlias("Root", "r") .Add(Expression.Eq("r.Code", rootCode)); } if (!String.IsNullOrEmpty(parentCode)) { crit.CreateAlias("Parent", "p") .Add(Expression.Eq("p.Code", parentCode)); } return(crit.UniqueResult <TreeListNode>()); }
public IEnumerable <ProfileHeader> GetProfileHeaders(long profileId) { ICriteria criteria = Session.CreateCriteria <ProfileHeader>(); criteria.CreateAlias("ProfileType", "profile").Add(Restrictions.Eq("profile.Id", profileId)); criteria.AddOrder(Order.Asc("OrderNumber")); return(criteria.SetCacheable(true).List <ProfileHeader>()); }
/// <summary> /// Join an association, assigning an alias to the joined entity /// </summary> /// <param name="criteria">criteria instance</param> /// <param name="expression">Lambda expression returning association path</param> /// <param name="alias">Lambda expression returning alias reference</param> /// <returns>criteria instance</returns> public static ICriteria CreateAlias(this ICriteria criteria, Expression <Func <object> > expression, Expression <Func <object> > alias) { string path = ExpressionProcessor.FindMemberExpression(expression.Body); string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body); return(criteria.CreateAlias(path, aliasContainer)); }
public ICriteria Apply(ICriteria criteria) { var associationPath = PropertyAccessor.PropertyNames[0]; var joinType = OuterJoin ? JoinType.LeftOuterJoin : JoinType.InnerJoin; criteria = criteria.CreateAlias(associationPath, associationPath, joinType); return(criteria); }
private static void BuildQueryFrom <T>(Query query, ICriteria criteria) { IList <ICriterion> critrions = new List <ICriterion>(); foreach (var c in query.Criteria) { ICriterion criterion; if (query.Aliases.Any()) { foreach (var alias in query.Aliases) { criteria.CreateAlias(alias.AssociationPath, alias.Alias); } } switch (c.CriteriaOperator) { case CriteriaOperator.Equal: criterion = Restrictions.Eq(c.PropertyName, c.Value); break; default: throw new InvalidEnumArgumentException(); } critrions.Add(criterion); } if (query.QueryOperator == QueryOperator.And) { var andSubQuery = Restrictions.Conjunction(); foreach (var criterion in critrions) { andSubQuery.Add(criterion); } criteria.Add(andSubQuery); } else { var orSubQuery = Restrictions.Disjunction(); foreach (var criterion in critrions) { orSubQuery.Add(criterion); } criteria.Add(orSubQuery); } foreach (var sub in query.SubQueries) { BuildQueryFrom <T>(sub, criteria); } }
public static IList <TreeListNode> GetTreeFromCode(Context context, String rootCode) { ICriteria crit = context.PersistenceSession.CreateCriteria(typeof(TreeListNode)); crit.CreateAlias("Parent", "p"); crit.Add(Expression.Eq("p.Code", rootCode)); IList <TreeListNode> listNodes = crit.List <TreeListNode>(); return(listNodes); }
static void AddAlias(String path, ICriteria criteria) { String[] names = path.Split('.'); for (int i = 0; i < names.Length - 1; i++) { if (criteria.GetCriteriaByAlias(names[i]) == null) { criteria.CreateAlias(names[i], names[i]); } } }
public static ICriteria CreateAlias <TEntity>(this ICriteria criteria, Expression <Func <TEntity, object> > expression, string newName, JoinType joinType) where TEntity : Entity { var associationpath = ExpressionHelper.GetAliasAssociationPath(expression); var aliasData = ExpressionHelper.GetAlias(expression); var alias = string.IsNullOrWhiteSpace(newName) ? aliasData.Alias : newName; return(criteria .CreateAlias(associationpath, alias, joinType)); }
public static ICriteria CreateAlias <TEntity>(this ICriteria criteria, Expression <Func <TEntity, object> > expression, JoinType joinType) where TEntity : Entity { var associationpath = ExpressionHelper.GetAliasAssociationPath(expression); var aliasData = ExpressionHelper.GetAlias(expression); var alias = aliasData.Alias; return(criteria .CreateAlias(associationpath, alias, joinType)); }
public bool PermissionCheck(string name, User user) { bool isGranted = false; // Check permission của role của user ICriteria criteria = _sessionManager.OpenSession().CreateCriteria(typeof(SpecialPermission)); criteria.CreateAlias("Role", "role"); criteria.CreateAlias("role.Users", "user"); ICriterion criterion = Expression.And(Expression.Eq("user.Id", user.Id), Expression.Eq("Name", name)); criteria.Add(criterion); criteria.SetProjection(Projections.RowCount()); int count = (int)criteria.List()[0]; // Check permission của user ICriteria criteria2 = _sessionManager.OpenSession().CreateCriteria(typeof(SpecialPermission)); ICriterion criterion2 = Expression.And(Expression.Eq("User", user), Expression.Eq("Name", name)); criteria2.Add(criterion2); criteria2.SetProjection(Projections.RowCount()); int count2 = (int)criteria2.List()[0]; isGranted = count + count2 > 0; if (isGranted) { return(true); } // Check có tồn tại permission đó không, nếu không tồn tại thì luôn là granted ICriteria pCriteria = _sessionManager.OpenSession().CreateCriteria(typeof(ModulePermission)); pCriteria.Add(Expression.Eq("Name", name)); pCriteria.SetProjection(Projections.RowCount()); int p = (int)pCriteria.List()[0]; return(p == 0); // Nếu không tồn tại thì là granted, nếu tồn tại thì đương nhiên là không granted }
/// <summary> /// Метод задает критерии поиска вакансий по фильтру /// </summary> /// <param name="crit"></param> /// <param name="filter"></param> public override void SetupFilter(ICriteria crit, VacancyFilter filter) { if (filter != null) { if (filter.SearchString != null) { crit.Add(Restrictions.Like("VacancyName", filter.SearchString, MatchMode.Anywhere)); } if (filter.Experience != null) { List <long> exp = new List <long>(); foreach (var e in filter.Experience) { exp.Add(e.Id); } crit.CreateAlias("Requirements", "VacancyExperience") .Add(Restrictions.In("VacancyExperience.id", exp)); } if (filter.StartDateRange != null) { if (filter.StartDateRange.From.HasValue) { crit.Add(Restrictions.Ge("Starts", filter.StartDateRange.From.Value)); } if (filter.StartDateRange.To.HasValue) { crit.Add(Restrictions.Le("Starts", filter.StartDateRange.To.Value)); } } if (filter.CompanyName.Id != 0) { crit.Add(Restrictions.Eq("Company.id", filter.CompanyName.Id)); } if (filter.EndDateRange != null) { if (filter.EndDateRange.From.HasValue) { crit.Add(Restrictions.Ge("Ends", filter.EndDateRange.From.Value)); } if (filter.StartDateRange.To.HasValue) { crit.Add(Restrictions.Le("Ends", filter.EndDateRange.To.Value)); } } if (filter.Statuses != null) { foreach (var s in filter.Statuses) { crit.Add(Restrictions.Eq("Status", filter.Statuses)); } } } }
public IList FeedbackReport(ICriterion criterion) { ICriteria criteria = _session.OpenSession().CreateCriteria(typeof(AnswerGroup)); criteria.CreateAlias("AnswerSheet", "sheet"); if (criterion != null) { criteria.Add(criterion); } criteria.AddOrder(Order.Asc("sheet.Date")); return(criteria.List()); }
//xxx public static IList <TimeSchedule> Find(Context context, string keyWord) { ICriteria crit = context.PersistenceSession.CreateCriteria <TimeSchedule>(); TreeListNode category = TreeListNode.FindByCode(context, "MFAccountSchedule"); crit.Add(Expression.Eq("Category", category)); crit.CreateAlias("Title", "title"); //crit.Add(Expression.Like("title", "")); return(crit.List <TimeSchedule>()); }
public static ICriteria AddAliases <T>(this IList <ProjectionColumn <T> > columns, ICriteria criteria) where T : DomainEntity { var aliasAndJoinTypeMap = new Cache <string, bool>(); columns.Each(c => c.AddAlias(aliasAndJoinTypeMap)); aliasAndJoinTypeMap.Each((alias, useOuterJoin) => { JoinType joinType = useOuterJoin ? JoinType.LeftOuterJoin : JoinType.InnerJoin; criteria = criteria.CreateAlias(alias, alias, joinType); }); return(criteria); }
// Das ist immernoch mit Kanonen auf Spatzen. Zur Zeit ist nur fuer Track.Property.Bpm u. .Year left join erwuenscht... private static void loadJunctions(Junction junction, ARelation aRelation, ISet<string> aliases, ICriteria criteria) { if(aRelation is ComplexRelation) { Junction newJunction = aRelation.BinaryRelator == Relator.Binary.AND ? new Conjunction() : new Disjunction() as Junction; foreach(ARelation relatum in aRelation.Relata) TrackSearch_Service.loadJunctions(newJunction, relatum, aliases, criteria); junction.Add(newJunction); } else { // if( aRelation is ASimpleRelation) ASimpleRelation aSimpleRelation = aRelation as ASimpleRelation; AbstractCriterion abstractCriterion; if(aSimpleRelation is SimpleRelation<string>) { if(aliases.Add(aSimpleRelation.Alias)) criteria.CreateAlias(aSimpleRelation.AssociationPath, aSimpleRelation.Alias); abstractCriterion = new InsensitiveLikeExpression( aSimpleRelation.SearchProperty, ((StringSearch)aSimpleRelation).Relatum, MatchMode.Anywhere); } else if(aSimpleRelation is SimpleRelation<int>) { if(aliases.Add(aSimpleRelation.Alias)) criteria.CreateAlias(aSimpleRelation.AssociationPath, aSimpleRelation.Alias, JoinType.LeftOuterJoin); abstractCriterion = new EqExpression( aSimpleRelation.SearchProperty, ((IntSearch)aSimpleRelation).Relatum); } else if( aSimpleRelation is Between_String ) { if(aliases.Add(aSimpleRelation.Alias)) criteria.CreateAlias(aSimpleRelation.AssociationPath, aSimpleRelation.Alias, JoinType.LeftOuterJoin); abstractCriterion = new BetweenExpression( aSimpleRelation.SearchProperty, ((Between_String)aSimpleRelation).Phrase1, ((Between_String)aSimpleRelation).Phrase2); } else if( aSimpleRelation is Between_Int ) { if(aliases.Add(aSimpleRelation.Alias)) criteria.CreateAlias(aSimpleRelation.AssociationPath, aSimpleRelation.Alias, JoinType.LeftOuterJoin); abstractCriterion = new BetweenExpression( aSimpleRelation.SearchProperty, ((Between_Int)aSimpleRelation).Phrase1, ((Between_Int)aSimpleRelation).Phrase2); } else { // if(aSimpleRelation is SimpleRelation<Ending.Attribute>) { abstractCriterion = new EqExpression( Track.Property.Ending.ToString(), new Ending(((EndingAttributeSearch)aSimpleRelation).Relatum)); } if(aSimpleRelation.UnaryRelator == Relator.Unary.NOT) abstractCriterion = Expression.Not(abstractCriterion); // else // if(aSimpleRelation.UnaryRelator == Relator.Unary.IS) junction.Add(abstractCriterion); } }
public override void Apply(ICriteria criteria) { if (!string.IsNullOrEmpty(Query)) { criteria.CreateAlias(string.Format("FREETEXTTABLE(Post, (Title, Body), '{0}')", Renderer.SqlEncode(Query)), "KEY_TBL", JoinType.InnerJoin).Add(Restrictions.Eq("Post.Post_Id", "KEY_TBL.[KEY]")); } if (TopicId != 0) { criteria.Add(Expression.Sql(string.Format("EXISTS ( SELECT * FROM PostTopic t WHERE t.Post_Id = this_.Post_Id AND t.Topic_Id = {0})", TopicId))); } if (DateStart != DateTime.MinValue) { criteria.Add(Expression.Ge("Created", DateStart)); } if (DateEnd != DateTime.MaxValue) { criteria.Add(Expression.Le("Created", DateEnd)); } if (PublishedOnly) { criteria.Add(Expression.Eq("Publish", true)); } if (DisplayedOnly) { criteria.Add(Expression.Eq("Display", true)); } base.Apply(criteria); }