Пример #1
0
        public virtual int DoUpdate <T>(T entity, Func <T, bool> resultAction = null) where T : class
        {
            var query = _queryGenerator.GenerateUpdate(entity, out IList <QueryInfo> queryParameters);
            var cmd   = new DotEntityDbCommand(DbOperationType.Update, query, queryParameters);

            DotEntityDbConnector.ExecuteCommand(cmd);
            return(cmd.GetResultAs <int>());
        }
Пример #2
0
        public void UpdateGenerator_Entity_Valid()
        {
            var product = new Product()
            {
                Id                 = 1,
                IsActive           = false,
                Price              = 55,
                ProductDescription = "Some description",
                ProductName        = "Somr proeud",
                DateCreated        = DateTime.Today
            };
            var sql      = generator.GenerateUpdate(product, out IList <QueryInfo> queryParameters);
            var expected = "UPDATE `Product` SET `ProductName` = @ProductName,`ProductDescription` = @ProductDescription,`DateCreated` = @DateCreated,`Price` = @Price,`IsActive` = @IsActive WHERE `Id` = @Id;";

            Assert.AreEqual(expected, sql);
            Assert.AreEqual(6, queryParameters.Count);
            Assert.AreEqual(product.ProductName, queryParameters.First(x => x.ParameterName == "ProductName").PropertyValue);
            Assert.AreEqual(product.ProductDescription, queryParameters.First(x => x.ParameterName == "ProductDescription").PropertyValue);
            Assert.AreEqual(product.Price, queryParameters.First(x => x.ParameterName == "Price").PropertyValue);
            Assert.AreEqual(product.DateCreated, queryParameters.First(x => x.ParameterName == "DateCreated").PropertyValue);
            Assert.AreEqual(product.IsActive, queryParameters.First(x => x.ParameterName == "IsActive").PropertyValue);
            Assert.AreEqual(product.Id, queryParameters.First(x => x.ParameterName == "Id").PropertyValue);
        }