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. 如何设置让iis服务器支持.apk文件的下载

    随着智能手机的普及,越来越多的人使用手机上网,很多网站也应手机上网的需要推出了网站客户端,.apk文件就是安卓(Android)的应用程序后缀名,默认情况下,使用IIS作为Web服务器的无法下载此文件 ...

  2. 使用 Daynamic 动态添加属性

    所谓的Dynamic 动态类型,页面也要是动态的(强撸) 很简单的 直接上代码: //案例一 DynamicpersonCollection = new ObservableCollection(); ...

  3. C# String.Format格式说明

    C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...

  4. bzoj4409&&bzoj4410&&bzoj4411[Usaco2016 Feb Platinum]题解

    辣鸡wyz最近状态奇差,于是想用usaco题找找手感,万万没想到被虐了一脸TAT 先贴代码,有空再填坑 4409[Usaco2016 Feb]Circular barn #include <io ...

  5. iOS推送处理

    iOS收到推送后,跳转到某一页面 字数1348 阅读1001 评论4 喜欢26 以前做过推送, 但只是那种最基本的广播推送(向所有安装appde设备通知), 列播组播这种对指定用户推送消息还没做过, ...

  6. android开发之画图版

    android开发之画图版 一.新的开始,也是新的挑战: 开始学习java,除了刚开始的时候有些难,觉得难有些晕,慢慢接触之后也就挺好的了, 学习了4天的安卓开发,完成了一个小程序,收获还是不小的:有 ...

  7. 又爱又恨系列之枚举enum

    其实枚举挺简单的,只不过以前没好好学,所以不知道这个东西,恩,现在梳理一下 整体而言,首先枚举是一个数据类型,这个数据类型和结构体有点像 可以分为三个层次 1.枚举数据类型定义 第一种:enum 枚举 ...

  8. hive 函数 Cube

    最近在优化一个报表系统.leader 提示我可以用cube函数.在此记录一下使用: 1) cube 简称数据魔方. 可以实现hive多个任意维度的查询. cube(a,b,c)  首先会对(a,b,c ...

  9. NameNode & DataNode

    NameNode类位于org.apache.hadoop.hdfs.server.namenode包下. NameNode serves as both directory namespace man ...

  10. ecshop 重置后台密码 MD5+salt

    ecshop密码加密方式: MD5 32位+salt,简单来说就是明文密码用MD5加密一次,然后在得到的MD5字符后边加上salt字段值(salt值为系统随机生成,生成以后不再改变)再进行一次MD5加 ...