public long Count(TSearchCriteria[] criteria, EntityFindOptions options) { // cannot defer count queries, because we have no way of proxying the result // without changing the return type of this method if (options.Defer) { throw new NotSupportedException("Count queries do not support the 'defer' option."); } var query = new HqlQuery(string.Format("select count(*) from {0} x", typeof(TEntity).Name)) { Cacheable = options.Cache }; // for a "count" query, sort conditions that may be present in the // criteria object must be ignored- therefore, only the conditions are added to the query var or = new HqlOr(); foreach (var c in criteria) { var and = new HqlAnd(HqlCondition.FromSearchCriteria("x", c)); if (and.Conditions.Count > 0) { or.Conditions.Add(and); } } if (or.Conditions.Count > 0) { query.Conditions.Add(or); } // expect exactly one integer result return(ExecuteHqlUnique <long>(query)); }
public IList <TEntity> FindAll(bool includeDeactivated, EntityFindOptions options) { var where = new TSearchCriteria(); // if the entity class supports deactivation, apply this condition if (!includeDeactivated && AttributeUtils.HasAttribute <DeactivationFlagAttribute>(typeof(TEntity))) { var propertyName = AttributeUtils.GetAttribute <DeactivationFlagAttribute>(typeof(TEntity)).PropertyName; var c = new SearchCondition <bool>(propertyName); c.EqualTo(false); where.SetSubCriteria(c); } return(Find(where, options)); }
public TEntity FindOne(TSearchCriteria[] criteria, EntityFindOptions options) { // we could probably implement this using NH proxies, but too much trouble right now if (options.Defer) { throw new NotSupportedException("FindOne queries do not support the 'defer' option."); } var results = Find(criteria, new SearchResultPage(0, 1), options); if (results.Count == 0) { throw new EntityNotFoundException(null); } return(results[0]); }
public IList <TEntity> Find(TSearchCriteria[] criteria, SearchResultPage page, EntityFindOptions options) { var query = new HqlProjectionQuery(new HqlFrom(typeof(TEntity).Name, "x")) { Page = page, Cacheable = options.Cache }; // add fetch joins foreach (var fetchJoin in GetDefaultFetchJoins()) { query.Froms[0].Joins.Add(new HqlJoin("x." + fetchJoin, null, HqlJoinMode.Inner, true)); } // apply lock hint if (options.LockForUpdate) { query.SetLockMode("x", LockMode.Upgrade); } var or = new HqlOr(); foreach (var c in criteria) { var and = new HqlAnd(HqlCondition.FromSearchCriteria("x", c)); if (and.Conditions.Count > 0) { or.Conditions.Add(and); } query.Sorts.AddRange(HqlSort.FromSearchCriteria("x", c)); } if (or.Conditions.Count > 0) { query.Conditions.Add(or); } return(ExecuteHql <TEntity>(query, options.Defer)); }
public IList <TEntity> Find(TSearchCriteria criteria, SearchResultPage page, EntityFindOptions options) { return(Find(new[] { criteria }, page, options)); }
public IList <TEntity> Find(TSearchCriteria[] criteria, EntityFindOptions options) { return(Find(criteria, new SearchResultPage(), options)); }
public long Count(TSearchCriteria criteria, EntityFindOptions options) { return(Count(new[] { criteria }, options)); }
public TEntity FindOne(TSearchCriteria criteria, EntityFindOptions options) { return(FindOne(new[] { criteria }, options)); }
public IList <TEntity> FindAll(EntityFindOptions options) { return(FindAll(true, options)); }