当前位置: 首页>>代码示例>>C#>>正文


C# ApplicationContext.Entry方法代码示例

本文整理汇总了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"); }
     }
 }
开发者ID:kyoryo,项目名称:DataStoreClient,代码行数:56,代码来源:BoardsControl.cs

示例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");
 }
开发者ID:alena-butkevich,项目名称:Document-Flow,代码行数:10,代码来源:AdminController.cs


注:本文中的ApplicationContext.Entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。