本文整理汇总了C#中Table.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Table.SaveChanges方法的具体用法?C# Table.SaveChanges怎么用?C# Table.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert_Transaction
public void Insert_Transaction()
{
using (var context = new Table())
{
int ID;
var userInfo = new UserVO() { UserName = "yy", GetDate = DateTime.Now };
// 将标识设置到标识字段
context.User.Insert(userInfo, true);
Assert.IsTrue(userInfo.ID > 0);
if (!(Table.Data.DbProvider is PostgreSqlProvider))
{
// 设置out ID
userInfo.ID++;
context.User.Insert(userInfo, out ID);
Assert.IsTrue(userInfo.ID > 0 && userInfo.ID == ID);
}
// 不同逻辑删除方式新入(主键为GUID)
context.Orders.Insert(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-1", CreateAt = DateTime.Now, CreateName = "用户1" });
context.OrdersAt.Insert(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-2", CreateAt = DateTime.Now, CreateName = "用户1" });
context.OrdersBool.Insert(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-3", CreateAt = DateTime.Now, CreateName = "用户1" });
context.OrdersNum.Insert(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-4", CreateAt = DateTime.Now, CreateName = "用户1" });
context.SaveChanges();
}
}
示例2: All
public void All()
{
var lst = Table.Data.UserRole.Cache;
var count = lst.Count;
var userCount = Table.Data.UserRole.Cache.GetValue(1, o => o.UserCount);
using (var context = new Table())
{
//context.User.ToEntity();
//context.User.ToList();
//context.User.Insert(new UserVO() { UserName = "xx" }, true);
context.UserRole.Insert(new UserRoleVO { Caption = "test", Descr = "cachetest" });
context.UserRole.Where(o => o.Caption == "test").Update(new UserRoleVO { Caption = "testUpdate" });
context.UserRole.AddUp(1, o => o.UserCount, 1);
context.SaveChanges();
}
Table.Data.UserRole.AddUp(1, o => o.UserCount, 1);
Assert.IsTrue(count + 1 == Table.Data.UserRole.Cache.Count, "缓存同步失败");
Assert.IsTrue(userCount + 2 == Table.Data.UserRole.Cache.GetValue(1, o => o.UserCount), "缓存同步失败");
}
示例3: Insert
public void Insert()
{
var count = Table.Data.User.Count();
var currentCount = 0;
UserVO info;
using (var context = new Table())
{
info = new UserVO() { UserName = "xx" };
context.User.Insert(info, true);
context.SaveChanges();
Assert.IsTrue(info.ID.GetValueOrDefault() > 0);
info = context.User.Desc(o => o.ID).ToEntity();
Assert.IsTrue(info.UserName == "xx");
currentCount = context.User.Count();
Assert.IsTrue(currentCount == count + 1);
}
Table.Data.User.Insert(new UserVO() { UserName = "yy" });
info = Table.Data.User.Desc(o => o.ID).ToEntity();
Assert.IsTrue(info.UserName == "yy");
currentCount = Table.Data.User.Count();
Assert.IsTrue(currentCount == count + 2);
// GUID
Table.Data.Orders.Insert(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "1234567890", CreateAt = DateTime.Now, CreateID = 1, CreateName = "用户1" });
}
示例4: Transaction_Delete
public void Transaction_Delete()
{
using (var context = new Table())
{
int? ID;
// 普通Where
ID = context.User.Desc(o => o.ID).GetValue(o => o.ID); context.User.Where(o => o.ID == ID).Delete(); Assert.IsFalse(context.User.Where(o => o.ID == ID).IsHaving());
// 重载
ID = context.User.Desc(o => o.ID).GetValue(o => o.ID); context.User.Delete(ID); Assert.IsFalse(context.User.Where(o => o.ID == ID).IsHaving());
// 批量
var IDs = context.User.Desc(o => o.ID).ToSelectList(5, o => o.ID);
context.User.Delete(IDs); Assert.IsFalse(context.User.Where(o => IDs.Contains(o.ID)).IsHaving());
// 缓存表
ID = context.UserRole.Cache.OrderByDescending(o => o.ID).GetValue(o => o.ID);
context.UserRole.Where(o => o.ID == ID).Delete();
Assert.IsFalse(context.UserRole.Cache.Where(o => o.ID == ID).IsHaving());
// 不同逻辑方式(主键为GUID)
var ID2 = context.Orders.Desc(o => o.ID).GetValue(o => o.ID); context.Orders.Delete(ID2); Assert.IsFalse(context.Orders.Where(o => o.ID == ID2).IsHaving());
ID2 = context.OrdersAt.Desc(o => o.ID).GetValue(o => o.ID);
context.OrdersAt.Delete(ID2); Assert.IsFalse(context.OrdersAt.Where(o => o.ID == ID2).IsHaving()); Assert.IsTrue(context.Orders.Where(o => o.ID == ID2).IsHaving());
context.OrdersBool.Delete(ID2); Assert.IsFalse(context.OrdersBool.Where(o => o.ID == ID2).IsHaving()); Assert.IsTrue(context.Orders.Where(o => o.ID == ID2).IsHaving());
context.OrdersNum.Delete(ID2); Assert.IsFalse(context.OrdersNum.Where(o => o.ID == ID2).IsHaving()); Assert.IsTrue(context.Orders.Where(o => o.ID == ID2).IsHaving());
context.OrdersBoolCache.Delete(ID2); Assert.IsFalse(context.OrdersBoolCache.Cache.Where(o => o.ID == ID2).IsHaving()); Assert.IsTrue(context.Orders.Where(o => o.ID == ID2).IsHaving());
// 手动SQL
ID = context.User.Desc(o => o.ID).GetValue(o => o.ID);
var table = context; table.ManualSql.Execute("DELETE FROM Members_User WHERE id = @ID", table.DbProvider.CreateDbParam("ID", ID));
Assert.IsFalse(context.User.Where(o => o.ID == ID).IsHaving());
context.SaveChanges();
}
}
示例5: Transaction_Insert
public void Transaction_Insert()
{
using (var context = new Table())
{
context.User.Select(o => o.ID).Asc(o => o.ID).ToEntity(1);
context.User.Select(o => o.ID).Where(1).ToEntity();
var info = context.User.Select(o => o.ID).Select(o => o.LogCount).Where(o => o.ID > 1 || o.UserName.IsEquals("xx")).Desc(o => o.ID).ToEntity();
Assert.IsTrue(info.ID > 1 && info.PassWord == null && info.GenderType == null && info.LoginIP == null && info.UserName == null && info.ID != null && info.LogCount != null);
// 缓存表
context.UserRole.Cache.First();
context.Orders.Where(Guid.NewGuid()).ToEntity();
context.OrdersAt.Where(Guid.NewGuid()).ToEntity(Guid.NewGuid());
context.OrdersBool.Where(Guid.NewGuid()).ToEntity(Guid.NewGuid());
context.OrdersNum.Where(Guid.NewGuid()).ToEntity(Guid.NewGuid());
context.OrdersBoolCache.Cache.First(o => o.ID != Guid.NewGuid());
// View
var accountInfo = context.Account.Select(o => o.ID).Select(o => o.Name).Where(o => o.ID > 1).ToEntity();
Assert.IsTrue(accountInfo.ID > 1 && accountInfo.Pwd == null && accountInfo.Name != null && accountInfo.ID != null);
// 存储过程
Assert.IsTrue(context.InfoUser.ToEntity(new InfoUserVO {ID = 3}).ID == 3);
// 配置SQL
context.GetNewUser.ToEntity();
// 手动SQL
var table = context;
table.ManualSql.ToEntity<UserVO>("Select * From Members_User Where UserName = @UserName", table.DbProvider.CreateDbParam("UserName", "steden1"));
context.SaveChanges();
}
}
示例6: Transaction_Update
public void Transaction_Update()
{
using (var context = new Table())
{
var userInfo = new UserVO() { UserName = "ffx", GetDate = DateTime.Now };
var ID = context.User.Desc(o => o.ID).GetValue(o => o.ID);
// 重载
context.User.Update(userInfo, ID);
// Where条件
context.User.Where(o => o.ID == ID).Update(userInfo);
// 批量
var IDs = context.User.Desc(o => o.ID).ToSelectList(5, o => o.ID);
context.User.Update(userInfo, IDs);
// 缓存表
ID = context.UserRole.Cache.OrderByDescending(o => o.ID).GetValue(o => o.ID);
context.UserRole.Update(new UserRoleVO { Caption = "标题", Descr = "不清楚" }, ID);
// 不同逻辑删除方式新入(主键为GUID)
var ID2 = context.Orders.Desc(o => o.ID).GetValue(o => o.ID);
context.Orders.Update(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-1", CreateAt = DateTime.Now, CreateName = "用户1" }, ID2);
context.OrdersAt.Update(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-2", CreateAt = DateTime.Now, CreateName = "用户1" }, ID2);
context.OrdersBool.Update(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-3", CreateAt = DateTime.Now, CreateName = "用户1" }, ID2);
context.OrdersNum.Update(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-4", CreateAt = DateTime.Now, CreateName = "用户1" }, ID2);
context.OrdersBoolCache.Update(new OrdersVO { ID = Guid.NewGuid(), OrderNo = "12345678-5", CreateAt = DateTime.Now, CreateName = "用户1" }, ID2);
// 手动SQL
ID = context.User.Desc(o => o.ID).GetValue(o => o.ID);
var table = context; table.ManualSql.Execute("UPDATE Members_User SET [email protected],PassWord [email protected] WHERE ID = @ID", table.DbProvider.CreateDbParam("UserName", "steden1"), table.DbProvider.CreateDbParam("PassWord", "steden1"), table.DbProvider.CreateDbParam("ID", ID));
context.SaveChanges();
}
}
示例7: Test
public void Test()
{
using (var context = new Table())
{
//var info = Table.Data.User.Where(o => o.ID > 0 && o.CreateAt < DateTime.Now).Desc(o => new { o.ID, LoginCount = o.LogCount }).Asc(o => o.GenderType).ToEntity();
var info = context.User.Where(o => o.ID > 0 && o.CreateAt < DateTime.Now).Desc(o => new {o.ID, LoginCount = o.LogCount}).Asc(o => o.GenderType).ToEntity();
info.PassWord = "77777";
context.User.Where(o => o.ID == 1).Update(info);
Table.TransactionInstance(context).ValueUser.GetValue(new ValueUserVO {ID = 1}, "");
info.ID = null;
info.PassWord = "00000New";
context.User.Insert(info);
context.User.Where(o => o.UserName.Contains("ste")).Count();
context.User.Where(o => "ste".Contains(o.UserName)).Count();
var a = new A {b = "steden"};
context.User.Where(o => a.b.Contains(o.UserName)).Count();
Table.TransactionInstance(context).InsertUser.Execute(new InsertUserVO {UserName = "now111", PassWord = "old222"});
context.User.Where(o => o.ID == 1).Update(info);
context.SaveChanges();
}
}
示例8: Insert_Transaction
public void Insert_Transaction()
{
using (var context = new Table())
{
context.SaveChanges();
}
}
示例9: GetValue_Transaction
public void GetValue_Transaction()
{
using (var context = new Table())
{
context.SaveChanges();
}
}
示例10: Insert_Transaction
public void Insert_Transaction()
{
using (var context = new Table())
{
context.ManualSql.Execute("INSERT INTO Members_User (UserName,PassWord) VALUES(@UserName,@PassWord)", context.DbProvider.CreateDbParam("UserName", "steden1"), context.DbProvider.CreateDbParam("PassWord", "steden1"));
context.SaveChanges();
}
}
示例11: Statistics_Transaction
public void Statistics_Transaction()
{
using (var context = new Table())
{
context.SaveChanges();
}
}
示例12: GetValue_Transaction
public void GetValue_Transaction()
{
using (var context = new Table())
{
Assert.IsTrue(!string.IsNullOrWhiteSpace(context.ValueUser.GetValue(new ValueUserVO { ID = 1 }, "")));
context.SaveChanges();
}
}
示例13: Insert_Transaction
public void Insert_Transaction()
{
using (var context = new Table())
{
// 配置SQL
context.InsertNewUser.Execute();
context.SaveChanges();
}
}
示例14: ToList_PageSplit
public void ToList_PageSplit()
{
using (var context = new Table())
{
// 取第2页的数据(每页显示3条数据)
Assert.IsTrue(context.User.ToList(3, 2).Count <= 3);
context.SaveChanges();
}
}
示例15: Insert_Transaction
public void Insert_Transaction()
{
using (var context = new Table())
{
var insertUser = new InsertUserVO() { PassWord = "123xx", UserName = "steden" };
// 存储过程
context.InsertUser.Execute(insertUser);
Assert.IsTrue(insertUser.ID > 0);
context.SaveChanges();
}
}