How to use context.Set and context.Entry, which ships with EF4.1 ?

Hello,

I am trying to implement a generic repository as explained on the following link :-
http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application However, I do not have options for context.Set or context.Entry, which Ships with EF 4.1 - is there some other way of doing it ? Please see problem code in bold below:-
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; // for EntityState using System.Data.Entity; using System.Linq.Expressions; // for Expression command using TasPOMark4.Models; namespace TasPOMark4.Models { public class GenericRepository<TEntity> where TEntity : class { internal TasEntities context; internal DbSet<TEntity> dbSet; public GenericRepository(TasEntities context) { this.context = context; this.dbSet = context.Set<TEntity>(); } public IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } if (orderBy != null) { return orderBy(query).ToList(); } else { return query.ToList(); } } public virtual TEntity GetByID(object id) { return dbSet.Find(id); } public virtual void Insert(TEntity entity) { dbSet.Add(entity); } public virtual void Delete(object id) { TEntity entityToDelete = dbSet.Find(id); Delete(entityToDelete); } public virtual void Delete(TEntity entityToDelete) { *//below Context.Entry does not exist* *//if (context.Entry(entityToDelete).State == EntityState.Detached)* *//if(context.ObjectStateManager.GetObjectStateEntry(entityToDelete) == EntityState.Detached)* *//{* dbSet.Attach(entityToDelete); //} dbSet.Remove(entityToDelete); } public virtual void Update(TEntity entityToUpdate) { dbSet.Attach(entityToUpdate); *//context.Entry does not exist* *//context.Entry(entityToUpdate).State = EntityState.Modified;* // GR skinning a cat (06/05/2011) context.ObjectStateManager.ChangeObjectState(entityToUpdate, EntityState.Modified); } } }
As you can see directly above, I have attempted to use context.ObjectStateManager.ChangeObjectState - is this correct ? Many thanks in advance for any help someone can provide, Graeme Edited by: user4487499 on -May- : Edited by: user4487499 on -May- : Edited by: user4487499 on -May- :

EF How to use context.Set and context.Entry, which ships with EF4.1 ?的更多相关文章

  1. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  2. Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别

    <context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config& ...

  3. Android 缓存目录 Context.getExternalFilesDir()和Context.getExternalCacheDir()方法

    一.基础知识 应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的.大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中.这样当该应用被卸载 ...

  4. context:exclude-filter 与 context:include-filter 转

    context:exclude-filter 与 context:include-filter 转 1 在主容器中(applicationContext.xml),将Controller的注解打消掉 ...

  5. [ERROR][org.springframework.web.context.ContextLoader][main] Context initialization failed org.sprin

    做一个SSH为基础框架的webapp小DEMO,复制了一把以前可以跑的代码,竟发现无法初始化数据源,报错如下: [ERROR][org.springframework.web.context.Cont ...

  6. <context:annotation-config> 和 <context:component-scan>的差别

    <context:annotation-config> is used to activate annotations in beans already registered in the ...

  7. <context:annotation-config> 跟 <context:component-scan>诠释及区别

    <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注 ...

  8. <context:annotation-config> 和 <context:component-scan>的区别

    转自:GOOD spring <context:annotation-config> 跟 <context:component-scan>诠释及区别 <context:a ...

  9. Spring context:component-scan中使用context:include-filter和context:exclude-filter

    Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version= ...

随机推荐

  1. bootstarp风格的toggle效果分享

    最近在写项目的时候想要一个这样的效果: 我知道这个效果在 flat-ui中有, 但是我又不想引用一整个flat-ui; 这个效果依赖html5的transition, 所以浏览器兼容成问题: 从fla ...

  2. C#-WinForm-客户端程序-Form基本属性

    WinForm - 客服端程序(C/S) WindowsForm 的简称 客户端应用程序:是需要安装在用户电脑上才可以使用的程序,代码部分在用户电脑上执行 特点:不需要联网也可以打开使用部分功能,但现 ...

  3. java内存管理机制

    JAVA 内存管理总结 1. java是如何管理内存的 Java的内存管理就是对象的分配和释放问题.(两部分) 分配 :内存的分配是由程序完成的,程序员需要通过关键字new 为每个对象申请内存空间 ( ...

  4. OPENGGL深度测试

    深度测试是为了解决那些在绘图过程中本应该被隐藏的面结果却出现了,例如: 绘图代码中先绘制了一个一个近处的立方体,后绘制了一个远处的立方体,结果在绘制过程中,远处的立方体总是在近处的立方体后绘制,所以在 ...

  5. HTML/HTML5/CSS/CSS3教程速查手册地址以及如何快速直到webkit的用法

    http://www.w3school.com.cn/ http://www.runoob.com/ 不过上面这两个都是标准的CSS和CSS3教程,针对一些类似-webkit-内核的样式没有公布. 下 ...

  6. Windows、Linux下文件操作(写、删除)错误的产生原因、及解决方法

    catalog . 引言 . Linux平台上涉及的File IO操作 . Windows平台上涉及的File IO操作 0. 引言 本文试图讨论在windows.linux操作系统上基于C库进行文件 ...

  7. fabric note

    #!/usr/bin/env python # -*- coding:utf-8 -*- from fabric.api import * from fabric.context_managers i ...

  8. 帝国cms搜索表单用法

    还有一些没有测试,用到了再补充. <form action="[!--news.url--]e/search/index.php" method="post&quo ...

  9. Autofac的高级使用——Autofac.2.6.3.862

    Autofac的高级使用——Autofac.2.6.3.862 目录(?)[-] 使用代码方式进行组件注册依赖服务类和组件类 使用配置文件进行组件注册不需要依赖 定义配置文件 读取config配置文件 ...

  10. VS快捷键大全(总结了一些记忆的口诀)

    相信.Net开发人员都想能够熟记各种VS快捷键以提高平时开发的效率,但苦于记忆能力太差而快捷键又特别多,特别烦,所以作罢! 下面我将简单介绍一下我记忆VS快捷键的一些方法,希望对大家有所帮助. 1.窗 ...