예제 #1
0
        public async ValueTask <TEntity> SingleAsync <TEntity>(Expression <Func <TEntity, object> > condition, Expression <Func <TEntity, object> > newExpression = null) where TEntity : Entity, new()
        {
            var properties = typeof(TEntity).GetReadWriteProperties();
            var members    = (newExpression?.Body as NewExpression)?.Members;
            var builder    = new QueryBuilder <TEntity>(Connector.Query, properties, members);

            if (members != null)
            {
                builder.BuildWhere(condition.Body, members);
            }
            else
            {
                builder.BuildWhereAll(condition.Body);
            }

            var rowData = await SelectAsync(builder);

            var objList = entityBuilder.CreateEntities(rowData, builder);

            if (objList.Length > 1)
            {
                Log.Message(LogTypes.Warning, "Result contains more than 1 element.");
            }

            return(objList.Length == 0 ? null : objList[0]);
        }
예제 #2
0
        public async Task <bool> AnyAsync <TEntity>(Expression <Func <TEntity, object> > condition) where TEntity : Entity, new()
        {
            var builder = new QueryBuilder <TEntity>(connectorQuery);
            var query   = builder.BuildWhereAll(condition.Body);

            using (var dataReader = await SelectAsync(query))
                return(dataReader.HasRows);
        }
예제 #3
0
        public async ValueTask <bool> AnyAsync <TEntity>(Expression <Func <TEntity, object> > condition) where TEntity : Entity, new()
        {
            var properties = typeof(TEntity).GetReadWriteProperties();
            var builder    = new QueryBuilder <TEntity>(Connector.Query, properties);

            builder.BuildWhereAll(condition.Body);

            var rowData = await SelectAsync(builder);

            return(rowData[0]?.Length > 0);
        }
예제 #4
0
        async ValueTask <InformationSchemaTable> GetTableInfoAsync(Expression <Func <InformationSchemaTable, object> > condition)
        {
            var properties = typeof(InformationSchemaTable).GetReadWriteProperties();
            var builder    = new QueryBuilder <InformationSchemaTable>(Connector.Query, properties);

            builder.BuildWhereAll(condition.Body);

            // Add the database name for this query.
            builder.SqlQuery.Replace($"FROM `{builder.PluralizedEntityName}`", $"FROM `information_schema`.`tables`");

            var rowData = await SelectAsync(builder);

            var entityList = entityBuilder.CreateEntities(rowData, builder);

            return(entityList.Length == 0 ? null : entityList[0]);
        }
예제 #5
0
        public async ValueTask <TEntity[]> WhereAsync <TEntity>(Expression <Func <TEntity, object> > condition, Expression <Func <TEntity, object> > newExpression = null) where TEntity : Entity, new()
        {
            var properties = typeof(TEntity).GetReadWriteProperties();
            var members    = (newExpression?.Body as NewExpression)?.Members;
            var builder    = new QueryBuilder <TEntity>(Connector.Query, properties, members);

            if (members != null)
            {
                builder.BuildWhere(condition.Body, members);
            }
            else
            {
                builder.BuildWhereAll(condition.Body);
            }

            var rowData = await SelectAsync(builder);

            return(entityBuilder.CreateEntities(rowData, builder));
        }
예제 #6
0
        public async Task <List <TEntity> > WhereAsync <TEntity>(Expression <Func <TEntity, object> > condition, Expression <Func <TEntity, object> > newExpression = null) where TEntity : Entity, new()
        {
            var query      = "";
            var properties = typeof(TEntity).GetReadWriteProperties();
            var members    = (newExpression?.Body as NewExpression)?.Members;
            var builder    = new QueryBuilder <TEntity>(connectorQuery, properties, members);

            if (members != null)
            {
                query = builder.BuildWhere(condition.Body, members);
            }
            else
            {
                query = builder.BuildWhereAll(condition.Body);
            }

            using (var dataReader = await SelectAsync(query))
                return(entityBuilder.CreateEntities(dataReader, builder).ToList());
        }