Frapid.Mapper.Sql.Limit C# (CSharp) Method

Limit() public method

public Limit ( DatabaseType type, int limit, int offset, string orderBy ) : Sql
type DatabaseType
limit int
offset int
orderBy string
return Sql
        public Sql Limit(DatabaseType type, int limit, int offset, string orderBy)
        {
            string token = "ORDER BY " + orderBy;

            if (type == DatabaseType.SqlServer)
            {
                var builder = new StringBuilder();
                builder.Append("ORDER BY " + orderBy);
                builder.Append(" OFFSET @0 ROWS");
                builder.Append(" FETCH NEXT @1 ROWS ONLY");
                token = this.ProcessToken(builder.ToString());
                return this.Append(new Sql(token, offset, limit));
            }


            token += " LIMIT @0 OFFSET @1";
            token = this.ProcessToken(token);
            return this.Append(new Sql(token, limit, offset));
        }

Usage Example

Ejemplo n.º 1
0
        public static async Task<DTO.Configuration> GetDefaultConfigurationAsync(string tenant)
        {
            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                var sql = new Sql("SELECT * FROM website.configurations");
                sql.Where("is_default=@0", true);
                sql.Limit(db.DatabaseType, 1, 0, "configuration_id");

                var awaiter = await db.SelectAsync<DTO.Configuration>(sql).ConfigureAwait(false);
                return awaiter.FirstOrDefault();
            }
        }
All Usage Examples Of Frapid.Mapper.Sql::Limit