Esempio n. 1
0
        public void UpdateManyToOneProperty()
        {
            // assemble
            var post = new Post();

            post.PostId = 1;
            post.Blog   = new Blog {
                BlogId = 1
            };
            ((ITrackedEntity)post).EnableTracking();
            post.Blog = new Blog {
                BlogId = 2
            };
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            var result = updateWriter.GenerateSql(new[] { post });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @p_1 where [PostId] = @p_2;", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@p_1");
            var param2 = result.Parameters.GetValueOfParameter("@p_2");

            Assert.IsType <int>(param1);
            Assert.IsType <int>(param2);
        }
Esempio n. 2
0
        public void Update(TEntity entity)
        {
            var adapter       = new EntityAdapter <TEntity>(entity, _map);
            var keyColumnName = _map.Key.GetColumnName();
            var values        = adapter.GetValues().Where(x => x.Key != keyColumnName);

            Command.Create(UpdateWriter <TEntity> .CreateStatement(new Update(values, _table, CreateEntityKeyFilter(entity, adapter)), _map), _profiler).
            ExecuteNonQuery(_connectionManager);
        }
Esempio n. 3
0
 public void UpdateSinglePropertyWorks() {
     var post = new Post();
     post.PostId = 1;
     post.Title = "Boo";
     ((ITrackedEntity)post).EnableTracking();
     post.Title = "New Boo";
     var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());
     var result = updateWriter.GenerateSql(new[] { post });
     Debug.Write(result.Sql);
     Assert.Equal("update [Posts] set [Title] = @p_1 where [PostId] = @p_2;", result.Sql);
 }
Esempio n. 4
0
        public void BulkUpdateIgnoresConstructorSetProperties()
        {
            // assemble
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            Expression <Func <ClassWithConstructor, bool> > predicate = p => p.Id == 1;
            var result = updateWriter.GenerateBulkSql(p => { }, new[] { predicate });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal(string.Empty, result.Sql); // Is this the correct result?
        }
Esempio n. 5
0
        public void UpdateSinglePropertyWorks()
        {
            var post = new Post();

            post.PostId = 1;
            post.Title  = "Boo";
            ((ITrackedEntity)post).EnableTracking();
            post.Title = "New Boo";
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());
            var result       = updateWriter.GenerateSql(new[] { post });

            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [Title] = @p_1 where [PostId] = @p_2;", result.Sql);
        }
Esempio n. 6
0
        public void BulkUpdateManyOneNullAddsNull()
        {
            // assemble
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            Expression <Func <Post, bool> > predicate = p => p.PostId == 1;
            var result = updateWriter.GenerateBulkSql(p => p.Blog = null, new[] { predicate });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@Blog");

            Assert.Null(param1);
        }
Esempio n. 7
0
        public void BulkUpdateManyToOnePropertyResolvesForeignKeyId()
        {
            // assemble
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            Expression <Func <Post, bool> > predicate = p => p.PostId == 1;
            var result = updateWriter.GenerateBulkSql(p => p.Blog = new Blog {
                BlogId = 1
            }, new[] { predicate });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@Blog");
            var param2 = result.Parameters.GetValueOfParameter("@l_1");

            Assert.IsType <int>(param1);
            Assert.IsType <int>(param2);
        }
Esempio n. 8
0
        public void UpdateManyToOneProperty() {
            // assemble
            var post = new Post();
            post.PostId = 1;
            post.Blog = new Blog { BlogId = 1 };
            ((ITrackedEntity)post).EnableTracking();
            post.Blog = new Blog { BlogId = 2 };
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            var result = updateWriter.GenerateSql(new[] { post });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @p_1 where [PostId] = @p_2;", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@p_1");
            var param2 = result.Parameters.GetValueOfParameter("@p_2");

            Assert.IsType(typeof(int), param1);
            Assert.IsType(typeof(int), param2);
        }
Esempio n. 9
0
        public void Update_Entity_Test()
        {
            var assignment = new Dictionary <string, object> {
                { "name", "bob" }, { "created", DateTime.MaxValue }, { "companyname", "Dunder Miflin" }, { "optout", true }
            };
            var update    = new Update(assignment, TableName, Operator.Create.FieldEqualsConstant("Id", Key));
            var statement = UpdateWriter <Entity> .CreateStatement(update, Map);

            statement.Result.ShouldEqual(Statement.ResultType.None);
            statement.Parameters.Count.ShouldEqual(5);
            statement.Parameters.First().Value.ShouldEqual("bob");
            statement.Parameters.Skip(1).First().Value.ShouldEqual(DateTime.MaxValue);
            statement.Parameters.Skip(2).First().Value.ShouldEqual("Dunder Miflin");
            statement.Parameters.Skip(3).First().Value.ShouldEqual(true);
            statement.Parameters.Skip(4).First().Value.ShouldEqual(Key);
            statement.Text.ShouldEqual(
                string.Format("UPDATE [{0}] SET [name] = @{1}, [created] = @{2}, [companyname] = @{3}, [optout] = @{4} WHERE ([id] = @{5})", TableName,
                              statement.Parameters.First().Key,
                              statement.Parameters.Skip(1).First().Key,
                              statement.Parameters.Skip(2).First().Key,
                              statement.Parameters.Skip(3).First().Key,
                              statement.Parameters.Skip(4).First().Key));
        }
Esempio n. 10
0
 private static UpdateWriter MakeTarget() {
     var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig(true));
     return updateWriter;
 }
Esempio n. 11
0
        public void BulkUpdateManyToOnePropertyResolvesForeignKeyId() {
            // assemble
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            Expression<Func<Post, bool>> predicate = p => p.PostId == 1;
            var result = updateWriter.GenerateBulkSql(p => p.Blog = new Blog { BlogId = 1 }, new[] { predicate });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@Blog");
            var param2 = result.Parameters.GetValueOfParameter("@l_1");

            Assert.IsType(typeof(int), param1);
            Assert.IsType(typeof(int), param2);
        }
Esempio n. 12
0
        public void BuldUpdateManyOneNullAddsNull() {
            // assemble
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig());

            // act
            Expression<Func<Post, bool>> predicate = p => p.PostId == 1;
            var result = updateWriter.GenerateBulkSql(p => p.Blog = null, new[] { predicate });

            // assert
            Debug.Write(result.Sql);
            Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result?

            var param1 = result.Parameters.GetValueOfParameter("@Blog");
            Assert.Null(param1);
        }
Esempio n. 13
0
        private static UpdateWriter MakeTarget()
        {
            var updateWriter = new UpdateWriter(new SqlServerDialect(), MakeConfig(true));

            return(updateWriter);
        }