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

In() public method

public In ( string token ) : Sql
token string
return Sql
        public Sql In(string token, params object[] args)
        {
            var parameters = args;

            if (args.Length == 1)
            {
                var candidate = args[0];
                bool isArray = candidate.GetType().IsArray;

                if (isArray)
                {
                    var enumerable = candidate as IEnumerable;
                    var innerParameter = new List<object>();

                    if (enumerable != null)
                    {
                        innerParameter.AddRange(enumerable.Cast<object>());
                    }

                    parameters = innerParameter.ToArray();
                }
            }


            int count = parameters.Length;
            string argTokens = string.Join(", ", Enumerable.Range(0, count).Select(x => "@" + x));

            token = token.Replace("@0", argTokens);

            token = this.ProcessToken(token);
            return this.Append(new Sql(token, parameters));
        }

Usage Example

Ejemplo n.º 1
0
        public async Task<IEnumerable<dynamic>> GetAsync(string resource, int userId, object[] resourceIds)
        {
            if(string.IsNullOrWhiteSpace(this.Database))
            {
                return null;
            }

            if(!this.SkipValidation)
            {
                if(!this.Validated)
                {
                    await this.ValidateAsync(AccessTypeEnum.Read, this.LoginId, this.Database, false).ConfigureAwait(false);
                }
                if(!this.HasAccess)
                {
                    Log.Information("Access to entity \"FlagView\" was denied to the user with Login ID {LoginId}. Resource: {Resource}, ResourceIds {ResourceIds}.", this.LoginId, resource, resourceIds);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var sql = new Sql("SELECT * FROM config.flag_view");
            sql.Where("resource=@0", resource);
            sql.And("user_id=@0", userId);
            sql.Append("AND");
            sql.In("resource_id IN (@0)", resourceIds);

            return await Factory.GetAsync<dynamic>(this.Database, sql).ConfigureAwait(false);
        }
All Usage Examples Of Frapid.Mapper.Sql::In