Example #1
0
        //public async Task<EntityList<Entities.Emploee>> SayHello(string name, int[] age, Guid id, DateTime birthday)
        //{
        //    //var vs = new Entities.Order();
        //    //vs.CreateById = Guid.Empty;
        //    //await EntityStore.SaveAsync(vs);
        //    return null;
        //}

        //[InvokePermission(Permissions.Admin || Permissions.Developer)]
        //public async Task SayHello(Entities.Emploee emp)
        //{
        //    await EntityStore.SaveAsync(emp);
        //}

        //public async Task<EntityBase> LoadEmploee(Guid id)
        //{
        //    return await EntityStore.LoadAsync<Entities.Emploee>(id);
        //}

        //public Task<bool> TypeIdTest()
        //{
        //    ulong baseType = 0;
        //    var res = baseType == Entities.Emploee.TypeId;
        //    return Task.FromResult(res);
        //}

        //public async Task DeleteTest()
        //{
        //    await EntityStore.DeleteAsync<Entities.Emploee>(Guid.Empty);
        //}

        //public async Task<object> Test()
        //{
        //    var q = new TableScan<Entities.OrgUnit>();
        //    q.Include(o => o.Parent.Name);
        //    return await q.ToListAsync();
        //}

        //public async Task<object> Test()
        //{
        //    var id = Guid.Empty;
        //    var childs = await EntityStore.LoadEntitySetAsync<Entities.OrgUnit, Entities.OrgUnit>(id, t => t.Childs);
        //    return childs;
        //}

        //public async Task<object> Test()
        //{
        //    var q = new TableScan<Entities.VehicleState>();
        //    q.Partitions.Equal(t => t.VehicleId, 1);
        //    //q.Partitions.Equal(t => t.CreateTime, new DateTime(2019, 1, 1));
        //    return await q.ToListAsync();
        //}

        //public async Task<object> Test()
        //{
        //	var q = new TableScan<Entities.VehicleState>();
        //	q.Filter(t => t.Lng > 12f && t.Lat > 20f);
        //	return await q.ToListAsync();
        //}

        //public async Task<object> Test(DateTime date)
        //{
        //    var q = new IndexScan<Entities.Emploee, Entities.Emploee.UI_Account_Password>();
        //    q.Keys.Equal(t => t.Account, "Admin");
        //    return await q.ToListAsync();
        //}

        //      public async Task Test()
        //{
        //	var obj = new Entities.City(214000);
        //	obj.Name = "Wuxi";
        //	await DataStore.DemoDB.SaveAsync(obj);
        //}

        //      public async Task<object> Test()
        //{
        //	var q = new SqlQuery<Entities.City>();
        //	q.Where(t => t.Code > 1 && t.Code < 10);
        //	return await q.ToListAsync();
        //}

        //public async Task<object> Test()
        //{
        //	var q = new SqlQuery<Entities.City>();
        //	q.Where(t => t.Code > 1 && t.Code < 10);
        //	return await q.ToListAsync(t=> t.Code);
        //}

        ///// <summary>
        ///// 测试更新命令及返回
        ///// </summary>
        //public async Task Test()
        //{
        //    var cmd = new SqlUpdateCommand<Entities.City>();
        //    cmd.Update(t => t.Persons = t.Persons + 1);
        //    cmd.Where(t => t.Code == 1);
        //    var outs = cmd.Output(t => t.Persons);
        //    await DataStore.DemoDB.ExecCommandAsync(cmd);
        //    if (outs.Count == 1 && outs[0] > 1) { }
        //}

        /// <summary>
        /// 测试更新命令及返回
        /// </summary>
        public async Task Test()
        {
            var cmd = new SqlUpdateCommand <Entities.City>();

            cmd.Update(t => t.Persons = t.Persons + 1);
            cmd.Where(t => t.Code == 1);
            var outs = cmd.Output(t => new { t.Persons, t.Code });
            await DataStore.DemoDB.ExecCommandAsync(cmd);

            if (outs.Count == 1 && outs[0].Persons > 1)
            {
            }
        }
Example #2
0
        public void BuildUpdateTest()
        {
            var model = MakeTestSqlModel();
            var mockRunntimeContext = new MockRuntimContext();

            Runtime.RuntimeContext.Init(mockRunntimeContext, 10410);
            mockRunntimeContext.AddModel(model);

            var q = new SqlUpdateCommand(model.Id);

            q.Update(q.T["Code"].Assign(q.T["Code"] + 1));
            q.Where(q.T["Code"] == 2);

            var outs = q.Output(r => r.GetInt32(0), q.T["Code"]);
            //var outs = q.Output(r => new { Code = r.GetInt32(0), Name = r.GetString(1) }, q.T["Code"], q.T["Name"]);
            //outs[0].Code == 3;

            var store = new PgSqlStore(StoreSettings);
            var cmd   = store.BuidUpdateCommand(q);

            Assert.True(cmd != null);
            output.WriteLine(cmd.CommandText);
            //Update "Emploee" t Set "Code" = "Code" + @p1 Where t."Code" = @p2 RETURNING "Code"
        }
Example #3
0
    //public Task LoadAsync<T>(T entity, Action<ISqlIncluder<T>> includer) { return null; }

    public Task ExecCommandAsync <TSource>(SqlUpdateCommand <TSource> cmd, DbTransaction txn = null) where TSource : SqlEntityBase
    {
        return(null);
    }
        public void BuildUpdate(IDbCommand command,
                                object data,
                                string tableName,
                                IFieldInfoCollection fields,
                                string whereExpression  = null,
                                OnConflictOption option = OnConflictOption.Default,
                                object keyValue         = null,
                                object extraPrams       = null)
        {
            if (command is null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (fields is null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("message", nameof(tableName));
            }

            var pkField = fields.PrimaryKeyField ?? throw new InvalidOperationException($"Primary Key field required for Update command");

            if (keyValue is null)
            {
                keyValue = pkField.GetFieldValue(data);
            }
            if (keyValue is null)
            {
                throw new InvalidOperationException($"{pkField.Property.Name} should not be null");
            }



            var columnNames       = new List <string>();
            var columnExpressions = new List <string>();

            foreach (var field in fields)
            {
                object value = field.GetFieldValueOrDefault(data) ?? DBNull.Value;
                var    param = MakeParameter(command, field, value);
                command.Parameters.Add(param);

                if ((field.PersistanceFlags & PersistanceFlags.OnUpdate) == PersistanceFlags.OnUpdate)
                {
                    columnNames.Add(field.Name);
                    columnExpressions.Add(param.ParameterName);
                }
            }

            if (extraPrams != null)
            {
                command.AddParams(extraPrams);
            }

            whereExpression = whereExpression ?? pkField.Name + " = " + GetParameterName(pkField);
            var where       = new WhereClause(whereExpression);
            var expression = new SqlUpdateCommand()
            {
                TableName        = tableName,
                ColumnNames      = columnNames,
                ValueExpressions = columnExpressions,
                ConflictOption   = option,
                Where            = where
            };

            command.CommandText = expression.ToString();
        }