本文整理汇总了C#中System.Db.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Db.SaveChangesAsync方法的具体用法?C# Db.SaveChangesAsync怎么用?C# Db.SaveChangesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Db
的用法示例。
在下文中一共展示了Db.SaveChangesAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public async Task<int> Save(long routeId, long stationId, int number)
{
if(routeId <= 0) throw new ArgumentException("routedId <= 0");
if(stationId <= 0) throw new ArgumentException("stationId <= 0");
using (var db = new Db())
{
using (var transtaction = db.Database.BeginTransaction(IsolationLevel.RepeatableRead))
{
try
{
var route = db.Routes.SingleOrDefault(r => r.Id == routeId);
if (route == null) throw new NullReferenceException("route");
var station = db.Stations.SingleOrDefault(r => r.Id == stationId);
if (station == null) throw new NullReferenceException("station");
var routeStation = new RouteStation() { Number = number, RouteId = routeId, StationId = stationId };
db.Entry(routeStation).State = EntityState.Added;
return await db.SaveChangesAsync();
}
catch (Exception ex)
{
Log.Error(ex.Message);
transtaction.Rollback();
throw;
}
}
}
}
示例2: Update
public async Task Update(Color t)
{
if (t == null)
throw new NullReferenceException("color");
using (var db = new Db())
{
db.Entry(t).State = EntityState.Modified;
await db.SaveChangesAsync();
}
}
示例3: Save
public async Task Save(Color t)
{
if(t == null)
throw new NullReferenceException("color");
using (var db = new Db())
{
try
{
db.Entry(t).State = EntityState.Added;
await db.SaveChangesAsync();
}
catch (Exception exception)
{
Log.Error(exception.Message);
throw;
}
}
}
示例4: Delete
public async Task<int> Delete(long routeId, Station station)
{
if(routeId <= 0) throw new ArgumentException("routeId <= 0");
if(station == null) throw new ArgumentNullException("station");
using (var db = new Db())
{
try
{
if (station.Id <= 0)
{
station = await _stationRepository.GetByLatLng(station.Latitude, station.Longitude);
if(station == null)throw new NullReferenceException("station");
}
var routeStation = new RouteStation() {RouteId = routeId, StationId = station.Id};
db.Entry(routeStation).State = EntityState.Deleted;
return await db.SaveChangesAsync();
}
catch (Exception ex)
{
Log.Error(ex.Message);
throw;
}
}
}