- 修复 新功能 BeginEdit bug;#397

This commit is contained in:
28810 2020-08-04 21:55:52 +08:00
parent 18cabd22b9
commit e092d10fee
2 changed files with 18 additions and 1 deletions

View File

@ -545,7 +545,7 @@ namespace FreeSql
/// <param name="data"></param> /// <param name="data"></param>
public void BeginEdit(List<TEntity> data) public void BeginEdit(List<TEntity> data)
{ {
if (data == null || data.Any() == false) return; if (data == null) return;
if (_table.Primarys.Any() == false) throw new Exception($"不可进行编辑,实体没有主键:{_db.OrmOriginal.GetEntityString(_entityType, data.First())}"); if (_table.Primarys.Any() == false) throw new Exception($"不可进行编辑,实体没有主键:{_db.OrmOriginal.GetEntityString(_entityType, data.First())}");
_statesEditing.Clear(); _statesEditing.Clear();
_dataEditing = data; _dataEditing = data;

View File

@ -552,6 +552,23 @@ namespace FreeSql.Tests
cts.RemoveAt(1); cts.RemoveAt(1);
Assert.Equal(3, repo.EndEdit()); Assert.Equal(3, repo.EndEdit());
g.sqlite.Delete<BeginEdit01>().Where("1=1").ExecuteAffrows();
repo = g.sqlite.GetRepository<BeginEdit01>();
cts = repo.Select.ToList();
repo.BeginEdit(cts);
cts.AddRange(new[] {
new BeginEdit01 { Name = "分类1" },
new BeginEdit01 { Name = "分类1_1" },
new BeginEdit01 { Name = "分类1_2" },
new BeginEdit01 { Name = "分类1_3" },
new BeginEdit01 { Name = "分类2" },
new BeginEdit01 { Name = "分类2_1" },
new BeginEdit01 { Name = "分类2_2" }
});
Assert.Equal(7, repo.EndEdit());
} }
class BeginEdit01 class BeginEdit01
{ {