Пример #1
0
 /// <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(this));
     }
     else
     {
         var colFilter = new DaughterColumns();
         return(colFilter.KeyColumn == IdValue);
     }
 }
Пример #2
0
        /// <summary>
        /// Execute a query and return the number of results
        /// </summary>
        /// <param name="where">A WhereDelegate that recieves a DaughterColumns
        /// and returns a IQueryFilter which is the result of any comparisons
        /// between DaughterColumns and other values
        /// </param>
        /// <param name="db"></param>
        public static long Count(WhereDelegate <DaughterColumns> where, Database database = null)
        {
            DaughterColumns c      = new DaughterColumns();
            IQueryFilter    filter = where (c);

            Database db    = database ?? Db.For <Daughter>();
            QuerySet query = GetQuerySet(db);

            query.Count <Daughter>();
            query.Where(filter);
            query.Execute(db);
            return(query.Results.As <CountResult>(0).Value);
        }
Пример #3
0
        /// <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 Daughter GetOneWhere(WhereDelegate <DaughterColumns> where, Database database = null)
        {
            var result = OneWhere(where, database);

            if (result == null)
            {
                DaughterColumns c      = new DaughterColumns();
                IQueryFilter    filter = where (c);
                result = CreateFromFilter(filter, database);
            }

            return(result);
        }
Пример #4
0
 public static async Task BatchQuery(int batchSize, WhereDelegate <DaughterColumns> where, Action <IEnumerable <Daughter> > batchProcessor, Database database = null)
 {
     await Task.Run(async() =>
     {
         DaughterColumns columns = new DaughterColumns();
         var orderBy             = Order.By <DaughterColumns>(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, (DaughterColumns) where (columns) && columns.KeyColumn > topId, orderBy, database);
         }
     });
 }
Пример #5
0
        /// <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 DaughterColumns
        /// and returns a IQueryFilter which is the result of any comparisons
        /// between DaughterColumns and other values
        /// </param>
        /// <param name="orderBy">
        /// Specifies what column and direction to order the results by
        /// </param>
        /// <param name="database"></param>
        public static DaughterCollection Top(int count, WhereDelegate <DaughterColumns> where, OrderBy <DaughterColumns> orderBy, Database database = null)
        {
            DaughterColumns c      = new DaughterColumns();
            IQueryFilter    filter = where (c);

            Database db    = database ?? Db.For <Daughter>();
            QuerySet query = GetQuerySet(db);

            query.Top <Daughter>(count);
            query.Where(filter);

            if (orderBy != null)
            {
                query.OrderBy <DaughterColumns>(orderBy);
            }

            query.Execute(db);
            var results = query.Results.As <DaughterCollection>(0);

            results.Database = db;
            return(results);
        }