Beispiel #1
0
        public static void TestSotredProcedureCommandSimpleAccess(ISqlSimpleAccess sqlSimpleAccess)
        {
            ISqlSimpleAccess simpleAccess = sqlSimpleAccess;

            simpleAccess.DefaultSimpleAccessSettings.DefaultCommandType = CommandType.StoredProcedure;

            Console.WriteLine("Test StoredProcedure Command with SimpleAccess");

            WriteLine("\nTesting simpleAccess.ExecuteEntities<Category>(\"Category_GetAll\", fieldsToSkip: null, propertyInfoDictionary:null, parameters:null);");
            var categories = simpleAccess.ExecuteEntities <Category>("dbo.Category_GetAll");

            WriteAll(categories);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Category>(\"dbo.Category_GetById\", fieldsToSkip: null, propertyInfoDictionary:null, parameters: 1.ToDataParam(\"Id\"));");
            var category = simpleAccess.ExecuteEntity <Category>("dbo.Category_GetById", parameters: 1.ToDataParam("Id"));

            WriteLine(category.ToString());

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Category>(\"dbo.Category_GetById\", fieldsToSkip: \"Description\", propertyInfoDictionary:null, parameters: 1.ToDataParam(\"Id\"));");
            category = simpleAccess.ExecuteEntity <Category>("dbo.Category_GetById", "Description", parameters: 1.ToDataParam("Id"));
            WriteLine(category.ToString());

            WriteLine("\nTesting simpleAccess.ExecuteNonQuery(\"dbo.Product_Insert\", fieldsToSkip: null, propertyInfoDictionary:null, parameters:dynamicParam);");
            var dynamicParam = new
            {
                Name        = "Shampu",
                CategoryId  = 1,
                IsActive    = true,
                ProductType = (short)ProductType.Liquid
                ,
                PricePerUnit    = 10.50f,
                PricePerPackage = 100.50d,
                UnitPerPackage  = (short)20
                ,
                AvailableTill = DateTime.Now,
                LastPurchase  = DateTime.Now
            };
            var recordAffected = simpleAccess.ExecuteNonQuery("dbo.Product_Insert", dynamicParam);

            WriteLine("Record affacted:{0}", recordAffected);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Product>(\"dbo.Product_GetAll\", fieldsToSkip: null, propertyInfoDictionary:null, parameters:nul);");
            var products = simpleAccess.ExecuteEntities <Product>("dbo.Product_GetAll", "Description", parameters: null);

            WriteAll(products);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<int>(\"dbo.Product_GetCount\", fieldsToSkip: null, propertyInfoDictionary:null, parameters:nul);");
            var productCount = simpleAccess.ExecuteScalar <int>("dbo.Product_GetCount");

            WriteLine("Total product count:{0}", productCount);

            Console.WriteLine("End Of StoredProcedure Command with SimpleAccess");
        }
Beispiel #2
0
        public static void TestTextCommandSimpleAccess(ISqlSimpleAccess sqlSimpleAccess)
        {
            ISqlSimpleAccess simpleAccess = sqlSimpleAccess;

            Console.WriteLine("Test TextCommand SimpleAccess");

            WriteLine("\nTesting simpleAccess.ExecuteEntities<Category>(query, fieldsToSkip: null, propertyInfoDictionary:null, parameters:null);");
            var categories = simpleAccess.ExecuteEntities <Category>("Select Id, Name, Description FROM Category", fieldsToSkip: null, propertyInfoDictionary: null, parameters: null);


            WriteAll(categories);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Category>(wherequery, fieldsToSkip: null, propertyInfoDictionary:null, parameters: 1.ToDataParam(\"Id\"));");
            var category = simpleAccess.ExecuteEntity <Category>("Select Id, Name, Description FROM Category WHERE Id = @Id", parameters: 1.ToDataParam("Id"));

            WriteLine(category.ToString());

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Category>(wherequery, fieldsToSkip: \"Description\", propertyInfoDictionary:null, parameters: 1.ToDataParam(\"Id\"));");
            category = simpleAccess.ExecuteEntity <Category>("Select Id, Name, Description FROM Category WHERE Id = @Id", "Description", parameters: 1.ToDataParam("Id"));
            WriteLine(category.ToString());

            WriteLine("\nTesting simpleAccess.ExecuteNonQuery(insertQuery, fieldsToSkip: null, propertyInfoDictionary:null, parameters:dynamicParam);");
            var dynamicParam = new { Name            = "Shampu", CategoryId = 1, IsActive = true, ProductType = (short)ProductType.Liquid
                                     , PricePerUnit  = 10.50f, PricePerPackage = 100.50d, UnitPerPackage = (short)20
                                     , AvailableTill = DateTime.Now, LastPurchase = DateTime.Now };
            var insertQuery    = @"INSERT INTO [dbo].[Product] ([Name],[CategoryId],[IsActive],[ProductType],[PricePerUnit],[PricePerPackage],[UnitPerPackage],[AvailableTill],[LastPurchase]) 
                                    VALUES(@Name, @CategoryId, @IsActive, @ProductType, @PricePerUnit, @PricePerPackage, @UnitPerPackage, @AvailableTill, @LastPurchase); ";
            var recordAffected = simpleAccess.ExecuteNonQuery(insertQuery, dynamicParam);

            WriteLine("Record affacted:{0}", recordAffected);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Product>(query, fieldsToSkip: null, propertyInfoDictionary:null, parameters:null);");
            var products = simpleAccess.ExecuteEntities <Product>("SELECT [Id],[Name],[CategoryId],[IsActive],[ProductType],[PricePerUnit],[PricePerPackage],[UnitPerPackage],[AvailableTill],[LastPurchase] FROM [dbo].[Product]", "Description", parameters: null);

            WriteAll(products);

            WriteLine("\nTesting simpleAccess.ExecuteEntity<Product>(query, fieldsToSkip: null, propertyInfoDictionary:null, parameters:nul);");
            var productCount = simpleAccess.ExecuteScalar <int>("SELECT COUNT([Id]) FROM Product;");

            WriteLine("Total product count:{0}", productCount);

            Console.WriteLine("End Of TextCommand with SimpleAccess");
        }