Пример #1
0
        public void InsertGenerator_EntityType_Valid()
        {
            var p        = new Product();
            var sql      = generator.GenerateInsert(p, out IList <QueryInfo> queryParameters);
            var expected = "INSERT INTO `Product` (`ProductName`,`ProductDescription`,`DateCreated`,`Price`,`IsActive`) VALUES (@ProductName,@ProductDescription,@DateCreated,@Price,@IsActive);SELECT last_insert_id() AS `Id`;";

            Assert.AreEqual(expected, sql);
            Assert.AreEqual(5, queryParameters.Count);
        }
Пример #2
0
        public void InsertGenerator_EntityType_Valid()
        {
            var p        = new Product();
            var sql      = generator.GenerateInsert(p, out IList <QueryInfo> queryParameters);
            var expected = "INSERT INTO [Product] ([ProductName],[ProductDescription],[DateCreated],[Price],[IsActive]) OUTPUT inserted.Id VALUES (@ProductName,@ProductDescription,@DateCreated,@Price,@IsActive);";

            Assert.AreEqual(expected, sql);
            Assert.AreEqual(5, queryParameters.Count);
        }
Пример #3
0
        public virtual int DoInsert <T>(T entity, Func <T, bool> resultAction = null) where T : class
        {
            var keyColumn = DataDeserializer <T> .Instance.GetKeyColumn();

            var query = _queryGenerator.GenerateInsert(entity, out IList <QueryInfo> queryParameters);
            var cmd   = new DotEntityDbCommand(DbOperationType.Insert, query, queryParameters, keyColumn);

            cmd.ProcessResult(result =>
            {
                var id = result as int? ?? Convert.ToInt32(result);
                DataDeserializer <T> .Instance.SetPropertyAs <int>(entity, keyColumn, id);
            });
            DotEntityDbConnector.ExecuteCommand(cmd);
            return(1);
        }