/// <summary> /// Gets a query filter that should uniquely identify /// the current instance. The default implementation /// compares the Id/key field to the current instance's. /// </summary> public override IQueryFilter GetUniqueFilter() { if (UniqueFilterProvider != null) { return(UniqueFilterProvider()); } else { var colFilter = new HouseParentColumns(); return(colFilter.KeyColumn == IdValue); } }
/// <summary> /// Execute a query and return the number of results /// </summary> /// <param name="where">A WhereDelegate that recieves a HouseParentColumns /// and returns a IQueryFilter which is the result of any comparisons /// between HouseParentColumns and other values /// </param> /// <param name="db"></param> public static long Count(WhereDelegate <HouseParentColumns> where, Database database = null) { HouseParentColumns c = new HouseParentColumns(); IQueryFilter filter = where (c); Database db = database ?? Db.For <HouseParent>(); QuerySet query = GetQuerySet(db); query.Count <HouseParent>(); query.Where(filter); query.Execute(db); return(query.Results.As <CountResult>(0).Value); }
/// <summary> /// Get one entry matching the specified filter. If none exists /// one will be created; success will depend on the nullability /// of the specified columns. /// </summary> /// <param name="where"></param> /// <param name="database"></param> public static HouseParent GetOneWhere(WhereDelegate <HouseParentColumns> where, Database database = null) { var result = OneWhere(where, database); if (result == null) { HouseParentColumns c = new HouseParentColumns(); IQueryFilter filter = where (c); result = CreateFromFilter(filter, database); } return(result); }
public static async Task BatchQuery(int batchSize, WhereDelegate <HouseParentColumns> where, Action <IEnumerable <HouseParent> > batchProcessor, Database database = null) { await Task.Run(async() => { HouseParentColumns columns = new HouseParentColumns(); var orderBy = Order.By <HouseParentColumns>(c => c.KeyColumn, SortOrder.Ascending); var results = Top(batchSize, where, orderBy, database); while (results.Count > 0) { await Task.Run(() => { batchProcessor(results); }); long topId = results.Select(d => d.Property <long>(columns.KeyColumn.ToString())).ToArray().Largest(); results = Top(batchSize, (HouseParentColumns) where (columns) && columns.KeyColumn > topId, orderBy, database); } }); }
/// <summary> /// Execute a query and return the specified number of values. This method /// will issue a sql TOP clause so only the specified number of values /// will be returned. /// </summary> /// <param name="count">The number of values to return. /// This value is used in the sql query so no more than this /// number of values will be returned by the database. /// </param> /// <param name="where">A WhereDelegate that recieves a HouseParentColumns /// and returns a IQueryFilter which is the result of any comparisons /// between HouseParentColumns and other values /// </param> /// <param name="orderBy"> /// Specifies what column and direction to order the results by /// </param> /// <param name="database"></param> public static HouseParentCollection Top(int count, WhereDelegate <HouseParentColumns> where, OrderBy <HouseParentColumns> orderBy, Database database = null) { HouseParentColumns c = new HouseParentColumns(); IQueryFilter filter = where (c); Database db = database ?? Db.For <HouseParent>(); QuerySet query = GetQuerySet(db); query.Top <HouseParent>(count); query.Where(filter); if (orderBy != null) { query.OrderBy <HouseParentColumns>(orderBy); } query.Execute(db); var results = query.Results.As <HouseParentCollection>(0); results.Database = db; return(results); }