本文整理汇总了C#中ApplicationContext.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationContext.Entry方法的具体用法?C# ApplicationContext.Entry怎么用?C# ApplicationContext.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationContext
的用法示例。
在下文中一共展示了ApplicationContext.Entry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunBoardAsync
public static async Task RunBoardAsync()
{
using (var client = new HttpClient())
{
//Send Http Request
client.BaseAddress = new Uri("http://localhost:12314/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//try
//{
// HTTP GET (Getting resource(s))
Console.WriteLine("Now consuming...");
HttpResponseMessage response = await client.GetAsync("api/Boards?q={}");
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
using (var db = new ApplicationContext())
{
Console.WriteLine("Success, Now reading...");
var board = response.Content.ReadAsAsync<dynamic>().Result;
Console.WriteLine("Id\tOwnerId\tTitle\tOrder\tCreatedAt\tLastUPdateTime");
foreach (var x in board.Data)
{
Board b = new Board();
int _emptyID = Convert.ToInt32(x.Id);
var v = db.Boards.Where(c => c.Id.Equals(_emptyID)).FirstOrDefault();
if (v != null)
{
v.Id = x.Id;
v.OwnerId = x.OwnerId;
v.Title = x.Title;
v.Order = x.Order;
v.CreatedAt = x.CreatedAt;
v.LastUpdateTime = x.LastUpdateTime;
Console.WriteLine("Updating data number " + v.Id + "");
db.Entry(v).State = EntityState.Modified;
}
else
{
b.Id = x.Id;
b.OwnerId = x.OwnerId;
b.Title = x.Title;
b.Order = x.Order;
b.CreatedAt = x.CreatedAt;
b.LastUpdateTime = x.LastUpdateTime;
db.Boards.Add(b);
Console.WriteLine("Adding data number " + b.Id + "");
}
db.SaveChanges();
}
}
}
else { Console.WriteLine("Unsuccessful"); }
}
}
示例2: EditPosition
public async Task<ActionResult> EditPosition(Position model)
{
using (ApplicationContext context = new ApplicationContext())
{
var position = await context.Positions.FindAsync(model.Id);
context.Entry(position).CurrentValues.SetValues(model);
context.SaveChanges();
}
return RedirectToAction("Positions");
}