本文整理汇总了C#中DataContext.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.SaveChangesAsync方法的具体用法?C# DataContext.SaveChangesAsync怎么用?C# DataContext.SaveChangesAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.SaveChangesAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRetrievedEventsAsync
private async Task ProcessRetrievedEventsAsync()
{
bool xAnythingHandled;
do
{
xAnythingHandled = false;
using (var xCtx = new DataContext())
{
foreach (var xEvent in (from item in xCtx.Events
where !item.Processed
orderby item.CreatedAt
select item).Take(50).ToArray())
{
if (!ShouldSkipEvent(xEvent.Type))
{
var xPayload = JsonConvert.DeserializeObject<JObject>(xEvent.Payload);
switch (xEvent.Type.ToLower())
{
case "pushevent":
HandleRetrievedPushEvent(xCtx, xEvent, xPayload);
break;
case "pullrequestevent":
HandleRetrievedPullRequestEvent(xCtx, xEvent, xPayload);
break;
default:
throw new Exception("Event not handled: '" + xEvent.Type + "'!");
}
}
//xEvent.Processed = true;
await xCtx.SaveChangesAsync();
// to handle:
//- PushEvent
//- PullRequestEvent
//xAnythingHandled = true;
}
}
}
while (xAnythingHandled);
}
示例2: SaveToDatabase
private static async Task SaveToDatabase(CancellationToken cancelToken, PostRequest request)
{
var context = new DataContext();
var sensor =
await
context.IotHubSensors.FirstOrDefaultAsync(x => x.Id == request.SensorId && x.HubId == request.HubId,
cancelToken);
if (sensor == null)
{
var hub = await context.IotHubs.FirstOrDefaultAsync(x => x.Id == request.HubId, cancelToken);
sensor = new IotHubSensor
{
Hub = hub,
Id = request.SensorId,
Description = ""
};
context.IotHubSensors.Add(sensor);
}
context.Ticks.Add(new SensorTick
{
Sensor = sensor,
Value = request.Value,
Timestamp = request.Timestamp
});
await context.SaveChangesAsync(cancelToken);
}