示例#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 SonColumns();
         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 SonColumns
        /// and returns a IQueryFilter which is the result of any comparisons
        /// between SonColumns and other values
        /// </param>
        /// <param name="db"></param>
        public static long Count(WhereDelegate <SonColumns> where, Database database = null)
        {
            SonColumns   c      = new SonColumns();
            IQueryFilter filter = where (c);

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

            query.Count <Son>();
            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 Son GetOneWhere(WhereDelegate <SonColumns> where, Database database = null)
        {
            var result = OneWhere(where, database);

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

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

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

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

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

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

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