1. Student studentToDelete;
  2. //1. Get student from DB
  3. using (var ctx = new SchoolDBEntities())
  4. {
  5. studentToDelete = ctx.Students.Where(s => s.StudentName == "Student1").FirstOrDefault<Student>();
  6. }
  7.  
  8. //Create new context for disconnected scenario
  9. using (var newContext = new SchoolDBEntities())
  10. {
  11. newContext.Entry(studentToDelete).State = System.Data.Entity.EntityState.Deleted;
  12.  
  13. newContext.SaveChanges();
  14. }

EntityFramework 学习 一 Delete Entity using DBContext in Disconnected Scenario的更多相关文章

  1. EntityFramework 学习 一 Add New Entity using DBContext in Disconnected Scenario

    using System; using System.Collections.Generic; public partial class Student { public Student() { th ...

  2. EntityFramework 学习 一 Update Existing Entity using DBContext in Disconnected Scenario

    using System; using System.Collections.Generic; public partial class Student { public Student() { th ...

  3. EntityFramework 学习 一 Update Entity Graph using DbContext:

    使用主键属性 每个实体必须有主键 默认值的id属性值必须为0 在context2中,它不知道实体的状态, 只能通过实体的主键来判断实体的状态 如果主键为0,则是新的对象,不为0 就是修改 Standa ...

  4. EntityFramework 学习 一 Add Entity Graph using DbContext:

    //Create student in disconnected mode Student newStudent = new Student() { StudentName = "New S ...

  5. EntityFramework 学习 一 Validate Entity

    可以为实体实现自定义验证,重写DBContext中的个ValidateEntity方法 protected override System.Data.Entity.Validation.DbEntit ...

  6. EntityFramework 学习 一 Colored Entity in Entity Framework 5.0

    You can change the color of an entity in the designer so that it would be easy to see related groups ...

  7. EntityFramework 学习 一 Explicit Loading with DBContext

    即使延迟加载不能使用,也可以通过明确的调用来延迟加载相关实体 使用DBEntryEntity来完成 using (var context = new SchoolDBEntities()) { //D ...

  8. Entity Framework DBContext 增删改查深度解析

    Entity Framework DBContext 增删改查深度解析 有一段时间没有更新博客了,赶上今天外面下雨,而且没人约球,打算把最近对Entity Framework DBContext使用的 ...

  9. DbContextScope,A simple and flexible way to manage your Entity Framework DbContext instances,by mehdime

    DbContextScope A simple and flexible way to manage your Entity Framework DbContext instances. DbCont ...

随机推荐

  1. background API

    语法: background:bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial| ...

  2. OpenCV for Python 学习笔记 三

    给源图像增加边界 cv2.copyMakeBorder(src,top, bottom, left, right ,borderType,value) src:源图像 top,bottem,left, ...

  3. 【Oracle】使用BBED跳过丢失的归档

    在recover datafile的过程其中假设丢失了须要的归档将使得recover无法进行.使用bbed工具能够跳过丢失的归档进行recover datafile. 实验步骤例如以下: SYS@OR ...

  4. Android开发系列之系统源码目录

    相信大家对于Google给出的那副经典Android架构图非常的熟悉,从下往上依次是Linux内核层(主要是负责硬件管理调度),HAL层(主要是硬件抽象层),libs层+Runtime,Framewo ...

  5. Jenkins入门(一)

    Jenkins就是一个Java Web应用,它主要是干什么呢? 其实很简单: 下载一个jenkins的war包,然后扔到tomcat 的webapps中,启动这个tomcat,访问jenkins应用即 ...

  6. 【Selenium + Python】之OSError: [WinError 6] 句柄无效。

    问题描述:执行多个用例的时候,会抛出异常: Traceback (most recent call last): File "F:\Demo\pomGisStu\gis\test_case\ ...

  7. PowerBuilder--Aes128加解密

    通过C#开发Com控件,注册到系统,然后由pb通过OLEObject进行调用 原文:https://www.cnblogs.com/eric_ibm/archive/2012/07/06/dll.ht ...

  8. BlockingQueue的使用 http://www.cnblogs.com/liuling/p/2013-8-20-01.html

    BlockingQueue的使用 本例介绍一个特殊的队列:BlockingQueue,如果BlockQueue 是空的,从BlockingQueue取东西的操作将会被阻断进入等待状态,直到Blocki ...

  9. winerror.h中的内容(可以查看last error对应)

    /************************************************************************* ** winerror.h -- error co ...

  10. 那不是Bug,是新需求

    原文作者:Jeff Atwood 自从我干上软件开发这一行.而且使用了Bug跟踪系统.我们在每个项目里都会纠结一个主要的问题:你怎么能把Bug与功能需求区分开来? 当然,假设程序崩溃了,这毫无疑问是B ...