- 优化 DbContext/Repository Orm 属性进行 CURD 与自身事务相同【新突破】;#270

This commit is contained in:
28810
2020-04-10 19:54:43 +08:00
parent d97dc3383c
commit 52fbe5ed86
17 changed files with 3884 additions and 3849 deletions

View File

@ -29,6 +29,13 @@ namespace FreeSql.Tests
item = repos.Find(item.Id);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(item));
repos.Orm.Insert(new AddUpdateInfo()).ExecuteAffrows();
repos.Orm.Insert(new AddUpdateInfo { Id = Guid.NewGuid() }).ExecuteAffrows();
repos.Orm.Update<AddUpdateInfo>().Set(a => a.Title == "xxx").Where(a => a.Id == item.Id).ExecuteAffrows();
item = repos.Orm.Select<AddUpdateInfo>(item).First();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(item));
repos.Orm.Delete<AddUpdateInfo>(item).ExecuteAffrows();
}
[Fact]
@ -122,6 +129,7 @@ namespace FreeSql.Tests
{
flowRepos = uow.GetRepository<FlowModel>();
flowRepos.Insert(flow);
flowRepos.Orm.Select<FlowModel>().ToList();
uow.Commit();
}
}
@ -158,6 +166,7 @@ namespace FreeSql.Tests
uow.Close();
var uowFlowRepos = uow.GetRepository<FlowModel>();
uowFlowRepos.Insert(flow);
uowFlowRepos.Orm.Select<FlowModel>().ToList();
//<2F>ѹرչ<D8B1><D5B9><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><E1BDBB>ûӰ<C3BB><EFBFBD>˴<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ر<EFBFBD><D8B1>ˣ<EFBFBD><CBA3><EFBFBD>CommitҲӦ<D2B2>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//uow.Commit();
}
@ -199,6 +208,7 @@ namespace FreeSql.Tests
{
var uowFlowRepos = uow.GetRepository<FlowModel>();
uowFlowRepos.Insert(flow);
uowFlowRepos.Orm.Select<FlowModel>().ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Insert/Update/Delete <20><><EFBFBD>ùر<C3B9>uow<6F>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B7A2><EFBFBD>
uow.Close();
uow.Commit();
@ -240,6 +250,7 @@ namespace FreeSql.Tests
{
var uowFlowRepos = uow.GetRepository<FlowModel>();
uowFlowRepos.Insert(flow);
uowFlowRepos.Orm.Select<FlowModel>().ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>commit<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1BDBB><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
//uow.Commit();
}

View File

@ -118,6 +118,8 @@ namespace FreeSql.Tests
};
ctx.AddRange(new[] { song1, song2, song3 });
ctx.Orm.Select<Tag>().Limit(10).ToList();
ctx.AddRange(
new[] {
new Song_tag { Song_id = song1.Id, Tag_id = tag1.Id },
@ -150,7 +152,7 @@ namespace FreeSql.Tests
using (var ctx = g.sqlite.CreateDbContext())
{
ctx.Options.EnableAddOrUpdateNavigateList = true;
var tags = ctx.Set<Tag>().Select.IncludeMany(a => a.Tags).ToList();
var tag = new Tag
@ -168,6 +170,9 @@ namespace FreeSql.Tests
}
};
ctx.Add(tag);
var tags2 = ctx.Orm.Select<Tag>().IncludeMany(a => a.Tags).ToList();
ctx.SaveChanges();
}
}
@ -179,10 +184,12 @@ namespace FreeSql.Tests
using (var ctx = g.sqlite.CreateDbContext())
{
ctx.Options.EnableAddOrUpdateNavigateList = true;
var tag = ctx.Set<Tag>().Select.First();
tag.Tags.Add(new Tag { Name = "sub3" });
tag.Name = Guid.NewGuid().ToString();
ctx.Update(tag);
var xxx = ctx.Orm.Select<Tag>().First();
ctx.SaveChanges();
}
}