Unit of work
Overview
A unit of work groups operations that commit or roll back together—essentially a transaction boundary with a friendlier API for entities.
Construction
Full name or shortcut:
c#
var work= DBCash.useUnitOfWork(0);
var work2= DBCash.useWork(0);From DBInstance:
c#
var db = DBCash.GetDBInstance(0);
var work3= db.useWork();Usage
c#
work.Insert(new HHDutyItem());
work.InsertRange(new List<HHDutyItem>());
work.Update(new HHDutyItem());
work.UpdateRange(new List<HHDutyItem>());
work.Delete(new HHDutyItem());
work.DeleteRange(new List<HHDutyItem>());
work.AddSQL(new SQLCmd("insert into HHDutyItem(id) values('123')"));
work.AddSQLs(new List<SQLCmd>() { });
work.InsertBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.set("id", 1)
.set("name", "123");
}
);
work.UpdateBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.set("sex", 1)
.set("name", "123")
.where("id", 1);
}
);
work.DeleteBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.where("id", 1);
}
);
work.Commit();Commit
c#
work.Commit();API reference
AddSQL / AddSQLs
c#
work.AddSQL(new SQLCmd("insert into HHDutyItem(id) values('123')"));c#
work.AddSQLs(new List<SQLCmd>() { });InsertBySQL
c#
work.InsertBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.set("id", 1)
.set("name", "123");
});Insert / InsertRange
c#
work.Insert(new HHDutyItem());c#
work.InsertRange(new List<HHDutyItem>());Update / UpdateRange
c#
work.Update(new HHDutyItem());c#
work.UpdateRange(new List<HHDutyItem>());UpdateBySQL
c#
work.UpdateBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.set("sex", 1)
.set("name", "123")
.where("id", 1);
});Delete / DeleteRange
c#
work.Delete(new HHDutyItem());c#
work.DeleteRange(new List<HHDutyItem>(
))DeleteById / DeleteByIds
c#
work.DeleteById<HHDutyItem>(1);c#
work.DeleteByIds<HHDutyItem>(new List<int>() { 1, 2, 3 });DeleteBySQL
c#
work.DeleteBySQL((kit) =>
{
kit.setTable("HHDutyItem")
.where("id", 1);
});Commit
c#
work.Commit();