询问者
如何定义Entity Framework的BaseContext

问题
-
public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } protected BaseContext() : base("connectionString") { } }
在这个页面看到的BaseContext以及代码示例
我的使用方法
public class Admin { public Guid ID { get; set; } public string Name { get; set; } public string Pass { get; set; } } public class UserContext : BaseContext<UserContext> { public DbSet<Admin> Admins { get; set; } }
使用时却提示上下文类型不受支持请问是怎么回事
- 已编辑 冰豆先生 2013年4月16日 7:43 修改标题
- 已移动 ThankfulHeart 2013年4月16日 8:27 EF问题
全部回复
-
具体是哪句话引发了异常?可以给出调试时候哪句话抛出异常?谢谢。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
尝试为其定义一个公开构造函数,并修改其访问权限:
public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } public BaseContext() : base("connectionString") { } public BaseContext() { } }
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats