mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 fsql.Insert(Dictionary<string, object>) 无实体类插入方法;#481
This commit is contained in:
@ -29,6 +29,31 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
}
|
||||
enum TestEnumInserTbType { str1, biggit, sum211 }
|
||||
|
||||
[Fact]
|
||||
public void InsertDictionary()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
dic.Add("id", 1);
|
||||
dic.Add("name", "xxxx");
|
||||
var diclist = new List<Dictionary<string, object>>();
|
||||
diclist.Add(dic);
|
||||
diclist.Add(new Dictionary<string, object>
|
||||
{
|
||||
["id"] = 2,
|
||||
["name"] = "yyyy"
|
||||
});
|
||||
|
||||
var sql1 = fsql.Insert(dic).AsTable("table1").ToSql();
|
||||
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(@id_0, @name_0)", sql1);
|
||||
var sql2 = fsql.Insert(diclist).AsTable("table1").ToSql();
|
||||
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(@id_0, @name_0), (@id_1, @name_1)", sql2);
|
||||
var sql3 = fsql.Insert(dic).AsTable("table1").NoneParameter().ToSql();
|
||||
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx')", sql3);
|
||||
var sql4 = fsql.Insert(diclist).AsTable("table1").NoneParameter().ToSql();
|
||||
Assert.Equal(@"INSERT INTO `table1`(`id`, `name`) VALUES(1, 'xxxx'), (2, 'yyyy')", sql4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AppendData()
|
||||
{
|
||||
|
Reference in New Issue
Block a user