本人通过跟踪sql语句得知 predicate如果为委托类型的时候,dbContext.Set<TEntity>().Where(predicate).ToList();对应的sql语句是 但是当predicate如果为表达式树的时候,语句如下, 所以我们尽量用表达式树传参,而不是单纯地lambda ...
分类:
数据库 时间:
2016-06-13 19:05:30
阅读次数:
382
本人建议尽量使用EntityState来表名Entry的状态,而不要使用Configuration.AutoDetectChangesEnabled自动状态跟踪,为什么我这么建议呢?他们到底有什么异同? 上面是一个Update操作 通过 dbContext.Entry<TEntity>(p).Sta ...
分类:
其他好文 时间:
2016-06-13 18:47:51
阅读次数:
137
public class Context : DbContext { public DbSet<Person> Person { get; set; } } public abstract class Entity { public long ID { get; set; } public abst ...
分类:
其他好文 时间:
2016-06-07 21:59:30
阅读次数:
114
1.定义泛型类 namespace Crm.Data.Logic.Repository{ public abstract class AbstractRepository<TC, T> : IDisposable where TC : DbContext, new() where T : class ...
分类:
其他好文 时间:
2016-06-02 13:36:57
阅读次数:
886
前言 终于到EF了,实在不好意思,最近有点忙,本篇离上一篇发布已经一个多星期了,工作中的小迭代告一段落,终于有点时间来继续我们的架构设计了,在这里先对大家表示歉意。 其实这段时间我并不是把这个系列给忘记了,而是一直在思考,想着接下来应该怎么写。因为园子里已经有很多非常优秀的EF的文章了,比如: 这些 ...
分类:
数据库 时间:
2016-06-01 16:49:20
阅读次数:
342
一、EF CodeFirst 根据实体创建数据库 1.新建好实体类 2.添加数据库上下文的类StudentInfoEntities:继承DbContext 3.配置Web.Config连接数据库字符串(name=“数据库上下文类的名称”) 4.写个controller运行代码,自动生成数据库 二、迁 ...
分类:
数据库 时间:
2016-05-24 20:29:50
阅读次数:
801
1、简单 count 会生成不必要的嵌套 var xs = (from x in dbContext.db_API_Operationallog where x.id<1 select 1 ).Count(); 结果: SELECT [GroupBy1].[A1] AS [C1] FROM ( SE ...
分类:
其他好文 时间:
2016-05-23 15:00:34
阅读次数:
137
定义一个ViewModel类 public class DirectorVM { [Key] public int DirectorID { get; set; } [Display(Name = "Director Name")] [DataType(DataType.Text)] public ...
分类:
数据库 时间:
2016-05-21 19:01:53
阅读次数:
175
1.DBContext的代码如下: 2.Menu类如下: Ctrl+F5运行没有问题。 3.修改Menu类,改成如下: 再次运行,发现此时报错 ...
分类:
其他好文 时间:
2016-05-21 17:34:44
阅读次数:
160
一、开发背景: 在用户登录的时候,验证用户和密码是否正确。验证通过后将用户名和用户ID保存下来以便后续数据更新时使用。 二、用户验证方法: 1、创建DBContext 对象。 ApplicationDbContext _context; //Controller构造函数 public FramCon ...
分类:
其他好文 时间:
2016-05-21 15:45:54
阅读次数:
202