Beispiel #1
0
        public static void Start()
        {
            VasilyRunner.Run();

            Console.WriteLine(SqlEntity <One> .Table);
            //table_one

            Console.WriteLine(SqlEntity <One> .Primary);
            //oid

            Console.WriteLine(SqlEntity <One> .SelectAll);
            //SELECT * FROM [table_one]

            Console.WriteLine(SqlEntity <One> .SelectAllByPrimary);
            //SELECT * FROM [table_one] WHERE [oid] = @oid

            Console.WriteLine(SqlEntity <One> .SelectAllIn);
            //SELECT * FROM [table_one] WHERE [oid] IN @keys

            Console.WriteLine(SqlEntity <One> .SelectAllWhere);
            //SELECT * FROM [table_one] WHERE


            Console.WriteLine(SqlEntity <One> .UpdateAllByPrimary);
            //UPDATE [table_one] SET [name]=@name,[create_time]=@create_time,[update_time]=@update_time,[age]=@age,[student_id]=@student_id WHERE [oid]=@oid

            Console.WriteLine(SqlEntity <One> .UpdateAllWhere);
            //UPDATE [table_one] SET [name]=@name,[create_time]=@create_time,[update_time]=@update_time,[age]=@age,[student_id]=@student_id WHERE


            Console.WriteLine(SqlEntity <One> .DeleteByPrimary);
            //DELETE FROM [table_one] WHERE [oid] = @oid

            Console.WriteLine(SqlEntity <One> .DeleteWhere);
            //DELETE FROM [table_one] WHERE


            Console.WriteLine(SqlEntity <One> .InsertAll);
            //INSERT INTO [table_one] ([name],[create_time],[update_time],[age],[student_id])VALUES(@name, @create_time, @update_time, @age, @student_id)

            Console.WriteLine(SqlEntity <One> .RepeateCount);
            //SELECT COUNT(*) FROM [table_one] WHERE [student_id] = @student_id

            Console.WriteLine(SqlEntity <One> .RepeateEntities);
            //SELECT * FROM [table_one] WHERE [student_id] = @student_id
            Console.WriteLine(SqlEntity <One> .RepeateId);
            //SELECT [oid] FROM [table_one] WHERE [student_id] = @student_id

            Console.WriteLine(SqlEntity <One> .SelectCount);
            //SELECT Count(*) FROM [table_one]
            Console.WriteLine(SqlEntity <One> .SelectCountWhere);
            //SELECT  Count(*) FROM [table_one] WHERE


            //操作对应的是DapperWrapper<One>
            One one = new One();
            DapperWrapper <One> dapper = new DapperWrapper <One>("key");

            dapper.IsRepeat(one);
        }
Beispiel #2
0
        public static IServiceCollection AddVasily(this IServiceCollection service, Action <ConnectOption> action = null)
        {
            ConnectOption options = new ConnectOption();

            action?.Invoke(options);
            VasilyRunner.Run();
            return(service);
        }
Beispiel #3
0
        public static void Start()
        {
            VasilyRunner.Run();
            Connector.Add <SqlConnection>("key", "链接字符串");
            Connector.Add <SqlConnection>("key-wr", "读-链接字符串", "写-链接字符串");
            Connector.AddRead <SqlConnection>("read1", "读-链接字符串");
            Connector.AddWrite <SqlConnection>("write2", "写-链接字符串");

            //创建driver的三种方式
            //wrapper = wrapper1 = wrapper2


            DapperWrapper <One> wrapper  = new DapperWrapper <One>("key");
            DapperWrapper <One> wrapper1 = "key";
            var wrapper2 = DapperWrapper <One> .UseKey("key");

            //wrapper4 = wrapper5 = wrapper6 = wrapper7
            DapperWrapper <One> wrapper4 = new DapperWrapper <One>("read1", "write2");
            DapperWrapper <One> wrapper5 = "key-wr | write2          ";
            var wrapper6 = DapperWrapper <One> .UseKey("key-wr", "write2");

            var wrapper7 = DapperWrapper <One> .UseKey("key-wr");



            One one  = new One();
            One one1 = new One();
            One one2 = new One();


            //两种调用方式

            //指定操作方式,RequestType赋值一次即可。
            //RequestType默认为 Complete;
            wrapper.RequestType = VasilyRequestType.Complete;
            wrapper.GetAll();

            //使用属性调用
            wrapper.Complete.GetAll();

            //获取所有元素
            wrapper.GetAll();
            wrapper.GetByPrimary(one);
            wrapper.GetsIn(1, 2, 3, 4);
            wrapper.GetIn(1);
            wrapper.IsRepeat(one);
            wrapper.NoRepeateAdd(one);
            wrapper.GetNoRepeateId <int>(one);
            wrapper.GetRepeates(one);
            wrapper.ModifyByPrimary(one, one1, one2);
            wrapper.Add(one, one1, one2);
            wrapper.SingleDeleteByPrimary(1);
            wrapper.EntitiesDeleteByPrimary(one, one1, one2);

            //SafeInsert = NoRepeateInsert + GetNoRepeateId
            wrapper.SafeAdd(one);
        }
Beispiel #4
0
        public static void Start()
        {
            VasilyRunner.Run();

            Console.WriteLine(RelationSql <Two, Two, One, Two_Parent> .Table);
            //table_relation

            Console.WriteLine(RelationSql <Two, Two, One, Two_Parent> .Primary);
            //rid


            Console.WriteLine(RelationSql <Two, Two, One, Two_Parent> .AddFromSource);
            //INSERT INTO [table_relation] ([rid],[one_id],[parent_id])VALUES(@rid, @oid, @rid)

            Console.WriteLine(RelationSql <Two, Two, One, Two_Parent> .AddFromTable);
            //INSERT INTO [table_relation] ([rid],[one_id],[parent_id])VALUES(@rid, @one_id, @parent_id)

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .DeleteAftFromSource);
            //DELETE FROM [table_relation] WHERE [one_id] = @oid AND [parent_id] = @rid

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .DeleteAftFromTable);
            //DELETE FROM [table_relation] WHERE [one_id] = @one_id AND [parent_id] = @parent_id

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .DeletePreFromSource);
            //DELETE FROM [table_relation] WHERE [three_id] = @tid

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .DeletePreFromTable);
            //DELETE FROM [table_relation] WHERE [three_id] = @three_id


            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .GetFromSource);
            //SELECT [three_id] FROM [table_relation] WHERE [one_id] = @oid AND [parent_id] = @rid

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .GetFromTable);
            //SELECT [three_id] FROM [table_relation] WHERE [one_id] = @one_id AND [parent_id] = @parent_id

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .ModifyFromSource);
            //UPDATE [table_relation] SET [three_id] = @tid WHERE [one_id] = @oid AND [parent_id] = @rid

            Console.WriteLine(RelationSql <Three, Two, One, Two_Parent> .ModifyFromTable);
            //UPDATE [table_relation] SET [three_id] = @three_id WHERE [one_id] = @one_id AND [parent_id] = @parent_id


            //操作对应的是DapperWrapper<Three, Two, One, Two_Parent>
            DapperWrapper <Three, Two, One, Two_Parent> dapper = new DapperWrapper <Three, Two, One, Two_Parent>("key");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            /*
             * Connector.Add<SqlConnection>("key:sql1", "连接字符串");
             * Connector.Add<SqlConnection>("key:sql2", "写-连接字符串", "读-连接字符串");
             *
             * DapperWrapper<One> wrapper = new DapperWrapper<One>("key:sql2");
             *
             * //重试3次
             * //取第1,3次的结果
             * int retry_count = 3;
             * int[] take_errors = new int[] { 1, 3};
             *
             * //准备实体
             * One entity = new One();
             * entity.age = 100;
             * entity.name = "小玉";
             *
             * //使用事务
             * wrapper.TransactionRetry((read_connection, write_connection) =>
             * {
             *  //wrapper.SafeAdd(check_repeate); Or
             *
             *  if (!wrapper.IsRepeat(entity))
             *  {
             *      wrapper.Add(entity);
             *  }
             *  else
             *  {
             *      //wrapper.ModifyByPrimary(check_repeate);
             *      wrapper.Modify(
             *          item => item == "age" & item == "name",
             *          entity
             *      );
             *  }
             *
             * }, retry_count,take_errors);
             *
             *
             * wrapper.Gets(item => item > "view" ^ item - "id" ^(10, 5),null);
             *
             * //Demo_Sql.Start();
             *
             * //Demo_RelationSql.Start();
             *
             *
             * //BenchmarkRunner.Run<Demo_Union>();*/
            //SqlMaker<Student> package = new SqlMaker<Student>();
            //var fields = typeof(SqlEntity<Student>).GetFields();
            //foreach (var item in fields)
            //{
            //    Console.WriteLine(item.Name + "\t:\t"+ item.GetValue(null));
            //}
            //new SqlMaker<SchoolClass>();
            //new SqlRelationMaker(typeof(RelationSql<Student, StudentAndClass, SchoolClass>));
            //fields = typeof(RelationSql<Student, StudentAndClass, SchoolClass>).GetFields();
            //foreach (var item in fields)
            //{
            //    Console.WriteLine(item.Name + "\t:\t" + item.GetValue(null));
            //}
            VasilyRunner.Run();
            new SqlRelationMaker(typeof(RelationSql <City, City, City_Anyname>));
            var fields = typeof(RelationSql <City, City, City_Anyname>).GetFields();

            foreach (var item in fields)
            {
                Console.WriteLine(item.Name + "\t:\t" + item.GetValue(null));
            }
            Console.ReadKey();
        }