EF6中的嵌套事务

时间:2015-02-05 04:11:00

标签: entity-framework

我有一个传入DBContext的方法(这只是POC代码)。

然后我尝试打开另一个嵌套事务,使用此代码

using (var cxt = new TestEntities(context.Database.Connection, false))
{           
  using (DbContextTransaction dbContextTransaction = cxt.Database.BeginTransaction())
  {

对“BeginTransaction”的调用会出现此错误:

An exception of type 'System.Data.Entity.Infrastructure.UnintentionalCodeFirstException' occurred in TestEF6.exe but was not handled in user code

Additional information: The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.  This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715

我有一个数据库优先模型 有线索吗?

此致 GregJF

0 个答案:

没有答案