示例#1
0
        public async Task <bool> UpdateAsync <TEntity>(Expression <Func <TEntity, bool> > condition, params Expression <Func <TEntity, object> >[] setExpressions) where TEntity : Entity, new()
        {
            var builder = new QueryBuilder <TEntity>(connectorQuery);

            var expressions = from c in setExpressions select((c.Body as UnaryExpression)?.Operand as MethodCallExpression) ?? c.Body as MethodCallExpression;

            var query = builder.BuildUpdate(expressions.ToArray(), true);

            query = builder.BuildUpdate(condition);

            return(await ExecuteAsync(query));
        }
示例#2
0
        public ValueTask <bool> UpdateAllAsync <TEntity>(params Expression <Func <TEntity, object> >[] setExpressions) where TEntity : Entity, new()
        {
            var builder     = new QueryBuilder <TEntity>(Connector.Query);
            var expressions = from c in setExpressions select((c.Body as UnaryExpression)?.Operand as MethodCallExpression) ?? c.Body as MethodCallExpression;

            builder.BuildUpdate(expressions.ToArray(), null);

            return(ExecuteAsync(builder));
        }
示例#3
0
        public async Task <bool> UpdateAsync <TEntity>(TEntity entity) where TEntity : Entity, new()
        {
            var type        = typeof(TEntity);
            var properties  = type.GetReadWriteProperties();
            var primaryKeys = type.GetTypeInfo().DeclaredProperties.Where(p => p.HasAttribute <PrimaryKeyAttribute>() || p.GetName() == "Id" || p.GetName() == type.Name + "Id").ToArray();
            var builder     = new QueryBuilder <TEntity>(connectorQuery);
            var query       = builder.BuildUpdate(entity, properties, primaryKeys);

            return(await ExecuteAsync(query));
        }