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


C# DeviceHiveContext.SaveChanges方法代码示例

本文整理汇总了C#中DeviceHive.Data.EF.DeviceHiveContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DeviceHiveContext.SaveChanges方法的具体用法?C# DeviceHiveContext.SaveChanges怎么用?C# DeviceHiveContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DeviceHive.Data.EF.DeviceHiveContext的用法示例。


在下文中一共展示了DeviceHiveContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
                throw new ArgumentNullException("deviceClass");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;

                    foreach (var equipment in deviceClass.Equipment.Where(e => e.ID > 0))
                    {
                        context.Entry(equipment).State = EntityState.Modified;
                    }
                    foreach (var equipment in context.Equipments.Where(e => e.DeviceClassID == deviceClass.ID))
                    {
                        if (context.Entry(equipment).State == EntityState.Unchanged)
                            context.Equipments.Remove(equipment);
                    }
                }
                
                context.SaveChanges();
            }
        }
开发者ID:EugeneTikhonov,项目名称:devicehive-.net,代码行数:26,代码来源:DeviceClassRepository.cs

示例2: Save

        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
                throw new ArgumentNullException("accessKey");

            using (var context = new DeviceHiveContext())
            {
                context.AccessKeys.Add(accessKey);
                if (accessKey.ID > 0)
                {
                    context.Entry(accessKey).State = EntityState.Modified;
                    
                    foreach (var permission in accessKey.Permissions.Where(e => e.ID > 0))
                    {
                        context.Entry(permission).State = EntityState.Modified;
                    }
                    foreach (var permission in context.AccessKeyPermissions.Where(e => e.AccessKeyID == accessKey.ID))
                    {
                        if (context.Entry(permission).State == EntityState.Unchanged)
                            context.AccessKeyPermissions.Remove(permission);
                    }
                }
                
                context.SaveChanges();
            }
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:26,代码来源:AccessKeyRepository.cs

示例3: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var command = context.DeviceCommands.Find(id);
         if (command != null)
         {
             context.DeviceCommands.Remove(command);
             context.SaveChanges();
         }
     }
 }
开发者ID:reven86,项目名称:framework,代码行数:12,代码来源:DeviceCommandRepository.cs

示例4: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var network = context.Networks.Find(id);
         if (network != null)
         {
             context.Networks.Remove(network);
             context.SaveChanges();
         }
     }
 }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:12,代码来源:NetworkRepository.cs

示例5: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var deviceClass = context.DeviceClasses.Find(id);
         if (deviceClass != null)
         {
             context.DeviceClasses.Remove(deviceClass);
             context.SaveChanges();
         }
     }
 }
开发者ID:reven86,项目名称:framework,代码行数:12,代码来源:DeviceClassRepository.cs

示例6: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var oauthClient = context.OAuthClients.Find(id);
         if (oauthClient != null)
         {
             context.OAuthClients.Remove(oauthClient);
             context.SaveChanges();
         }
     }
 }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:12,代码来源:OAuthClientRepository.cs

示例7: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var equipment = context.Equipments.Find(id);
         if (equipment != null)
         {
             context.Equipments.Remove(equipment);
             context.SaveChanges();
         }
     }
 }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:12,代码来源:EquipmentRepository.cs

示例8: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var notification = context.DeviceNotifications.Find(id);
         if (notification != null)
         {
             context.DeviceNotifications.Remove(notification);
             context.SaveChanges();
         }
     }
 }
开发者ID:reven86,项目名称:framework,代码行数:12,代码来源:DeviceNotificationRepository.cs

示例9: Delete

 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var user = context.Users.Find(id);
         if (user != null)
         {
             context.Users.Remove(user);
             context.SaveChanges();
         }
     }
 }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:12,代码来源:UserRepository.cs

示例10: Save

        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
                throw new ArgumentNullException("deviceClass");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:reven86,项目名称:framework,代码行数:15,代码来源:DeviceClassRepository.cs

示例11: Save

        public void Save(Network network)
        {
            if (network == null)
                throw new ArgumentNullException("network");

            using (var context = new DeviceHiveContext())
            {
                context.Networks.Add(network);
                if (network.ID > 0)
                {
                    context.Entry(network).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:15,代码来源:NetworkRepository.cs

示例12: Save

        public void Save(OAuthClient oauthClient)
        {
            if (oauthClient == null)
                throw new ArgumentNullException("oauthClient");

            using (var context = new DeviceHiveContext())
            {
                context.OAuthClients.Add(oauthClient);
                if (oauthClient.ID > 0)
                {
                    context.Entry(oauthClient).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:15,代码来源:OAuthClientRepository.cs

示例13: Save

        public void Save(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            using (var context = new DeviceHiveContext())
            {
                context.Users.Add(user);
                if (user.ID > 0)
                {
                    context.Entry(user).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:15,代码来源:UserRepository.cs

示例14: Save

        public void Save(Equipment equipment)
        {
            if (equipment == null)
                throw new ArgumentNullException("equipment");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Attach(equipment.DeviceClass);
                context.Equipments.Add(equipment);
                if (equipment.ID > 0)
                {
                    context.Entry(equipment).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:16,代码来源:EquipmentRepository.cs

示例15: Save

        public void Save(DeviceNotification notification)
        {
            if (notification == null)
                throw new ArgumentNullException("notification");

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(notification.Device);
                context.DeviceNotifications.Add(notification);
                if (notification.ID > 0)
                {
                    context.Entry(notification).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
开发者ID:reven86,项目名称:framework,代码行数:16,代码来源:DeviceNotificationRepository.cs


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