从我的项目中删除 .edmx

Posted

技术标签:

【中文标题】从我的项目中删除 .edmx【英文标题】:Removing .edmx from my project 【发布时间】:2012-04-13 21:55:26 【问题描述】:

我在现有的 DB-Entity Framework 4.1 中使用 Code First,在我的项目中,我添加了 .edmx 文件并生成了架构,查看存储过程一切正常,一切都在生产中。

我的问题来了

1- I moved my .edmx file,.tt to other project
2- Removed from working project
3- Copy all schema,view,DBContext everything related to .edmx generated to folder called Entities.
4- Removed matadata information from connection string which is in web.config

之后我无法运行项目错误来的错误是

System.Data.DataException was unhandled by user code
  Message=An exception occurred while initializing the database. See the InnerException for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
       at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
       at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
       at QTrac.DAL.RepositoryBase`1.Get(Expression`1 filter, Func`2 orderBy, Nullable`1 take, String includeProperties, Boolean tracking) in D:\QTrack\Project-NewQTrac\QTrac\QTrac.DAL\RepositoryBase.cs:line 39
       at QTrac.DAL.EquipStateRepository.GetEquipStates(Nullable`1 active) in D:\QTrack\Project-NewQTrac\QTrac\QTrac.DAL\EquipStateRepository.cs:line 25
       at QTrac.BLL.AssetManagementService.GetEquipStates(Nullable`1 active) in D:\QTrack\Project-NewQTrac\QTrac\BL\AssetManagementService.cs:line 68
       at QTrac.Web.Controllers.AssetManagementController.Grid_PopulateEquipmentStateCombo() in D:\QTrack\Project-NewQTrac\QTrac\QTrac.Web\Controllers\AssetManagementController.cs:line 135
       at QTrac.Web.Controllers.AssetManagementController.Detail() in D:\QTrack\Project-NewQTrac\QTrac\QTrac.Web\Controllers\AssetManagementController.cs:line 38
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: System.Data.EntityException
       Message=The underlying provider failed on Open.
       Source=System.Data.Entity
       StackTrace:
            at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
            at System.Data.EntityClient.EntityConnection.Open()
            at System.Data.Objects.ObjectContext.EnsureConnection()
            at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
            at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
            at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
            at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
            at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
            at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
            at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
            at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
            at System.Data.Entity.Internal.InternalContext.QueryForModelHash()
            at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata)
            at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
            at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3()
            at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       InnerException: System.Transactions.TransactionManagerCommunicationException
            Message=Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.
            Source=System.Transactions
            StackTrace:
                 at System.Transactions.Oletx.OletxTransactionManager.ProxyException(COMException comException)
                 at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)
                 at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)
                 at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)
                 at System.Transactions.EnlistableStates.Promote(InternalTransaction tx)
                 at System.Transactions.Transaction.Promote()
                 at System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction)
                 at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
                 at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
                 at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
                 at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
                 at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
                 at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
                 at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
                 at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
                 at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
                 at System.Data.SqlClient.SqlConnection.Open()
                 at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
            InnerException: System.Runtime.InteropServices.COMException
                 Message=The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024)
                 Source=System.Transactions
                 ErrorCode=-2147168220
                 StackTrace:
                      at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, ITransactionShim& transactionShim)
                      at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)
                 InnerException: 

请告诉我这是什么问题,请告诉我解决方案。

谢谢

【问题讨论】:

InnerException 包含什么? 【参考方案1】:

由于 .edmx 文件实际上只是一个 xml 文件,我建议在记事本中打开该文件并检查以确保引用指向新项目而不是旧项目。

【讨论】:

edmx 文件在新项目中运行良好,但我从其中删除该项目的项目无法正常运行,您可以看到错误。 你还在旧项目的某个地方引用它吗?尝试删除实体框架的所有库引用,这样编译器会告诉你是否在代码中的任何位置引用了 edmx。

以上是关于从我的项目中删除 .edmx的主要内容,如果未能解决你的问题,请参考以下文章

如何从我的 Eclipse 项目中删除 javascript 验证?

如何从我的项目中删除不必要的资源?

Cocoapod:为啥 Xcode 构建过程试图找到已经从我的项目中删除的库

如何从我的包用户的导入语句中删除输出文件夹?

同一个 .net 解决方案中的多个 edmx

从firebase中删除项目的正确方法