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. poj3177 && poj3352 边双连通分量缩点

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12676   Accepted: 5368 ...

  2. jsp 中的js 与 jstl 运行的先后顺序

    在jsp 中运行下面的代码,结论是:js 中可以使用 标签,js 的注释 对标签无效-- 有知道原理的吗<c:set var="flag" value="false ...

  3. Http 和TCP的关系,TCP长连接和短连接有什么区别?

    HTTP 协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用.由于HTTP在 ...

  4. js 上传文件模拟Form 表单

    使用FormData对象 在本文章中 创建一个FormData对象 使用HTML表单来初始化一个FormData对象 使用FormData对象发送文件 利用FormData对象,你可以使用一系列的键值 ...

  5. 【C++实现python字符串函数库】strip、lstrip、rstrip方法

    [C++实现python字符串函数库]strip.lstrip.rstrip方法 这三个方法用于删除字符串首尾处指定的字符,默认删除空白符(包括'\n', '\r', '\t', ' '). s.st ...

  6. BZOJ 1142: [POI2009]Tab

    1142: [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 213  Solved: 80[Submit][Status][D ...

  7. 如何解决Response.Redirect方法传递汉字丢失或乱码问题?

    为了确保传递的汉字被正确地接收,可以在传值之前使用Server对象的UrlEncode方法对所传递的汉字进行URL编码.代码如下: String name = Server.UrlEncode(&qu ...

  8. iOS内存管理个人总结

    一.变量,本质代表一段可以操作的内存,她使用方式无非就是内存符号化+数据类型 1.保存变量有三个区域: 1>静态存储区 2>stack 3>heap 2.变量又根据声明的位置有两种称 ...

  9. JavaWeb---总结(九)通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下: 创建一个DrawImage Servlet,用来生成验证码图片  1 package gacl. ...

  10. python 时间类型和相互转换

    time有四种类型(time, datetime, string, timestamp) 1. time string string是最简单的表示time的方式 如如下代码生成的即为string &g ...