EF给我生产错误而不是Dev。

时间:2013-04-15 17:00:48

标签: entity-framework entity-framework-5

我有以下生成的EF模型使用的连接字符串。它在我的本地计算机上正常工作但是当我部署时,我得到以下错误。我在SO上看了多次引用的网址:http://blogs.teamb.com/craigstuntz/2010/08/13/38628/如果它有答案,我就不会看到它。

我正在粘贴下面的错误

  <add name="svcodecampEntitiesAllTables" connectionString="metadata=res://*/EFModel.ModelAllTables.csdl|res://*/EFModel.ModelAllTables.ssdl|res://*/EFModel.ModelAllTables.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=svcc;integrated security=True;persist security info=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

{"message":"An error has occurred.","exceptionMessage":"Unable to load the specified metadata resource.","exceptionType":"System.Data.MetadataException","stackTrace":"   at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n   at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n   at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n   at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n   at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)\r\n   at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()\r\n   at System.Data.Common.Utils.Memoizer`2.Result.GetValue()\r\n   at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)\r\n   at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)\r\n   at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()\r\n   at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)\r\n   at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)\r\n   at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()\r\n   at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()\r\n   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()\r\n   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()\r\n   at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)\r\n   at WebAPI.rest.AttendeesDashboardController.Get(String userSearch, Nullable`1 presentersOnly, Nullable`1 currentCodeCampYearOnly, Nullable`1 start, Nullable`1 limit) in c:\\VCProject\\SVCodeCampWeb\\WebAPI\\rest\\AttendeesDashboardController.cs:line 97\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}

3 个答案:

答案 0 :(得分:5)

我也有这个问题。我通过显式命名包含模型的程序集来修复它。

因此,如果您的模型位于“Product.DAL.dll”中,而不是:

  metadata=res://*/EFModel.ModelAllTables.csdl|...

放:

  metadata=res://Product.DAL/EFModel.ModelAllTables.csdl|...

用于所有3个元数据资源

答案 1 :(得分:0)

您必须添加对包含edmx图的项目的引用,并更改Nunit项目中的连接字符串

更改

<add name="ContainerName" connectionString="metadata=res://*/Diagram.csdl|re.....

通过元数据中3个位置的库名称

<add name="ContainerName"connectionString="metadata=res://File.Data/Diagram.csdl|res://File.Data/Diagra...

“File.Data”是File.Data.dll,由包含图表的项目生成的库

答案 2 :(得分:0)

我有同样的问题并通过运行自定义工具解决了。右键单击 Model.tt 文件并单击运行自定义工具并对 context.tt 文件和 Model.edmx 文件重复相同的操作。重新构建应用程序将起作用。