예제 #1
0
        static void TestDbContext()
        {
            try
            {
                WriteToDatabase();
            }
            catch (Exception ex)
            {
                var a = ex;
            }

            void WriteToDatabase()
            {
                var dbConnectionBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();

                dbConnectionBuilder.DataSource     = "115.159.55.137,1999";
                dbConnectionBuilder.UserID         = "chenguangxu";
                dbConnectionBuilder.Password       = "******";
                dbConnectionBuilder.InitialCatalog = "Manager.Account";
                dbConnectionBuilder.ConnectTimeout = 10;

                DbConnectionManager.Register(dbConnectionBuilder.InitialCatalog, new MsSqlConnectionProvider(10, dbConnectionBuilder.ConnectionString));
                EntitySchemaManager.LoadEntity(typeof(Entity));
                var option = new DbContextOptions();

                option.ExceptionHandling = ExceptionHandling.Skip;
                using (var dbContext = new DbContext(option))
                {
                    var dbSet = dbContext.Set <Entity>();
                    dbSet.Add(new Entity()
                    {
                        ID = 2, Name = "a2"
                    });
                    dbSet.Add(new Entity()
                    {
                        ID = 3, Name = "a3"
                    });
                    try
                    {
                        dbContext.SaveChanges();
                    }
                    finally
                    {
                        foreach (var row in dbSet.RowEntries)
                        {
                            var a = row.State;
                        }
                    }
                }
            }
        }
예제 #2
0
        static void TestDatabase()
        {
            var dbConnectionBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();

            dbConnectionBuilder.DataSource     = "115.159.55.137,1999";
            dbConnectionBuilder.UserID         = "chenguangxu";
            dbConnectionBuilder.Password       = "******";
            dbConnectionBuilder.InitialCatalog = "Manager.Account";
            DbConnectionManager.Register(dbConnectionBuilder.InitialCatalog, new MsSqlConnectionProvider(10, dbConnectionBuilder.ConnectionString));
            EntitySchemaManager.LoadEntity(typeof(Entity));
            foreach (var view in EntitySchemaManager.Schemas)
            {
                EntityUtils.CheckSchema(view);
            }
        }
예제 #3
0
        static void TestExpression1()
        {
            EntitySchemaManager.LoadEntity <SceneObject>();
            var view          = EntitySchemaManager.GetSchema <SceneObject>(true);
            var dbProvider    = new Framework.Data.MsSql.MsSqlConnectionProvider(1, "");
            var commandStruct = dbProvider.CreateCommand <SceneObject>(view.Name, DbCommandMode.Select);
            var fields        = new List <long>()
            {
            };

            var guid = Guid.NewGuid();

            commandStruct.Where(p => (p.ID == 0 || fields.Contains(p.ID)) && !p.Deleted);
            commandStruct.OrderBy(p => p.Guid, true);
            //commandStruct.Where(p => fields.Contains(p.ID) && !p.Deleted);
            var commandText = commandStruct.CommandText;
        }
예제 #4
0
        static void TestExpression2()
        {
            EntitySchemaManager.LoadEntity <SceneObject>();
            var view          = EntitySchemaManager.GetSchema <SceneObject>(true);
            var dbProvider    = new Framework.Data.MsSql.MsSqlConnectionProvider(1, "");
            var commandStruct = dbProvider.CreateCommand <SceneObject>(view.Name, DbCommandMode.Select);

            commandStruct.Columns.Add(SqlExpression.As(SqlExpression.Function("count", SqlExpression.Symbol("*")), "Count"));
            var fields = new List <long>()
            {
                4, 3
            };

            commandStruct.Where(p => (p.Function == null || fields.Contains(p.ID)) && !p.Deleted);
            commandStruct.OrderBy(p => p.ID);

            var commandText = commandStruct.CommandText;
        }
예제 #5
0
        static void TestExpression3()
        {
            var sb = new System.Data.SqlClient.SqlConnectionStringBuilder();

            sb.DataSource     = "115.159.55.137,1999";
            sb.UserID         = "chenguangxu";
            sb.Password       = "******";
            sb.InitialCatalog = "BlingAccount";
            EntitySchemaManager.LoadEntity <SceneObject>();
            var view          = EntitySchemaManager.GetSchema <SceneObject>(true);
            var dbProvider    = new Framework.Data.MsSql.MsSqlConnectionProvider(1, sb.ConnectionString);
            var commandStruct = dbProvider.CreateCommand <SceneObject>(view.Name, DbCommandMode.Select);
            var keys          = new List <long>()
            {
                1, 5, 7, 9
            };

            commandStruct.Where(p => p.Name != null && keys.Contains(p.ID));
            commandStruct.OrderBy(p => p.ID);
            var a = dbProvider.Select(commandStruct);
        }