mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 增加 ColumnAttribute 可插入(CanInsert)、可更新(CanUpdate);#99
This commit is contained in:
@ -125,7 +125,6 @@ namespace FreeSql.Tests.DataAnnotations
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
}
|
||||
|
||||
class TestIsIgnore
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
@ -133,5 +132,45 @@ namespace FreeSql.Tests.DataAnnotations
|
||||
[Column(IsIgnore = true)]
|
||||
public bool isignore { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanInsert_CanUpdate()
|
||||
{
|
||||
var item = new TestCanInsert { title = "testtitle", testfield1 = 1000, testfield2 = 1000 };
|
||||
var sql = g.mysql.Insert(item).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("INSERT INTO `TestCanInsert`(`id`, `title`, `testfield2`) VALUES(?id_0, ?title_0, ?testfield2_0)", sql);
|
||||
|
||||
Assert.Equal(1, g.mysql.Insert(item).ExecuteAffrows());
|
||||
var find = g.mysql.Select<TestCanInsert>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.title, find.title);
|
||||
Assert.NotEqual(item.testfield1, find.testfield1);
|
||||
Assert.Equal(0, find.testfield1);
|
||||
Assert.Equal(item.testfield2, find.testfield2);
|
||||
|
||||
item.title = "testtitle_update";
|
||||
item.testfield2 = 0;
|
||||
sql = g.mysql.Update<TestCanInsert>().SetSource(item).ToSql().Replace("\r\n", "");
|
||||
Assert.Equal($"UPDATE `TestCanInsert` SET `id` = ?p_0, `title` = ?p_1, `testfield1` = ?p_2 WHERE (`id` = '{item.id}')", sql);
|
||||
|
||||
Assert.Equal(1, g.mysql.Update<TestCanInsert>().SetSource(item).ExecuteAffrows());
|
||||
find = g.mysql.Select<TestCanInsert>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.title, find.title);
|
||||
Assert.Equal(item.testfield1, find.testfield1);
|
||||
Assert.NotEqual(item.testfield2, find.testfield2);
|
||||
Assert.Equal(1000, find.testfield1);
|
||||
}
|
||||
class TestCanInsert
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
public string title { get; set; }
|
||||
[Column(CanInsert = false)]
|
||||
public long testfield1 { get; set; }
|
||||
[Column(CanUpdate = false)]
|
||||
public long testfield2 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user