Replies: 1 comment 1 reply
-
建实体类进行查询 https://github.com/dotnetcore/FreeSql/wiki/%E5%8A%A8%E6%80%81%E6%93%8D%E4%BD%9C //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.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
在动态查询的时候,代码如下:
对于返回的数据需要通过字段名称来获取,如果没有指定返回的字段名称,由于大小写的问题,可能会出现字段对应不上;如果能指定返回的字段方法,就不会出差错了。
目前可以通过
WithSql
来实现,但是多个数据库存在方言问题,不知道后续可否支持。Beta Was this translation helpful? Give feedback.
All reactions