public async Task CreateTableNoTableName()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists createtablenotablename;");

                {
                    var storage  = CreateStorage(StorageMode.Insert);
                    var dfc      = new DataContext(null, null, null, null);
                    var typeName = typeof(CreateTableEntity2);
                    var entity   = new CreateTableEntity2();

                    var items = new List <CreateTableEntity2> {
                        entity
                    };
                    dfc.AddData(typeName, items);
                    await storage.HandleAsync(dfc);

                    var list = (await conn.QueryAsync <CreateTableEntity2>("SELECT * FROM createtablenotablename"))
                               .ToList();
                    Assert.Single(list);
                    entity = list.First();
                    Assert.Equal("xxx", entity.Str1);
                    Assert.Equal("yyy", entity.Str2);
                    Assert.Equal(655, entity.Required);
                    Assert.Equal(0, entity.Decimal);
                    Assert.Equal(600, entity.Long);
                    Assert.Equal(400, entity.Double);
                    Assert.Equal(200.0F, entity.Float);
                    await conn.ExecuteAsync("drop table if exists createtablenotablename;");
                }
            }
        }
Beispiel #2
0
        public async Task CreateTableNoTableName()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists createtablenotablename;");

                var services = SpiderProvider.Value.CreateScopeServiceProvider();
                var storage  = CreateStorage(StorageType.Insert);
                var dfc      = new DataFlowContext(null, services);
                var typeName = typeof(CreateTableEntity2).FullName;
                var entity   = new CreateTableEntity2();
                dfc.Add(typeName, entity.GetTableMetadata());
                var items = new ParseResult <CreateTableEntity2>
                {
                    entity
                };
                dfc.AddParseItem(typeName, items);
                await storage.HandleAsync(dfc);

                var list = (await conn.QueryAsync <CreateTableEntity2>("SELECT * FROM createtablenotablename")).ToList();
                Assert.Single(list);
                entity = list.First();
                Assert.Equal("xxx", entity.Str1);
                Assert.Equal("yyy", entity.Str2);
                Assert.Equal(655, entity.Required);
                Assert.Equal(0, entity.Decimal);
                Assert.Equal(600, entity.Long);
                Assert.Equal(400, entity.Double);
                Assert.Equal(200.0F, entity.Float);
                await conn.ExecuteAsync("drop table if exists createtablenotablename;");
            }
        }