无实体时同步表结构
#1501
Replies: 1 comment 2 replies
-
可以,即将集成了一个功能,原先是一直交给外部动态编译处理的。 //v3.2.695 emit 动态创建实体类型
var table = fsql.CodeFirst.DynamicEntity("user", new TableAttribute { Name = "t_user" })
.Property("id", typeof(int), new ColumnAttribute { IsIdentity = true, IsPrimary = rue })
.Property("username", typeof(string), new ColumnAttribute { StringLength = 32 })
.Build();
//如果有必要,请将 table 缓存起来
Dictionary<string, object> dict = new Dictionary<string, object>();
dict["id"] = 1;
dict["username"] = "xxx";
//将字典转化成 type 对应的 object
object obj = table.CreateInstance(dict);
//插入
fsql.Insert<object>().AsType(table.Type).AppendData(obj).ExecuteAffrows();
//更新
fsql.Update<object>().AsType(table.Type).SetSource(obj).ExecuteAffrows();
//插入或更新
fsql.InsertOrUpdate<object>().AsType(table.Type).SetSource(obj).ExecuteAffrows();
//删除
fsql.Delete<object>().AsType(table.Type).WhereDynamic(obj).ExecuteAffrows();
//查询
List<object> objs = fsql.Select<object>().AsType(table.Type).ToList();
//等等... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
在没有实体的情况下,是否可以新增通过 TableInfo 、或 List (ColumnInfo) 同步表结构 ??
使用场景:数据同步工具,将A库同步到B库,A可能涉及到表的新增。
思路是
1、先获取 A 库中的表,得到 TableInfo (或用代码动态构建TableInfo 、或List(ColumnInfo) );
2、 判断 B 库表是否存在,不存在则使用 TableInfo 创建表(或 用 TableInfo 直接同步表结构 );
之前提供的思路是用动态实体,但在实际使用的过程中动态实体局限性比较大,无法满足需求,希望能提供一种其他的方式
Beta Was this translation helpful? Give feedback.
All reactions