0

我意识到这个问题在此之前已经被问过并解决了很多次,并且有很多有用的帖子,比如这个...... http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ 但不幸的是没有任何建议对我有用,所以我发帖是希望有人能发现我没见过的东西。

我有一个数据库项目 Sp_CodeGenerator - 我已连接到数据库。我的连接字符串是

<add name="AdWorksLTEntities" connectionString="metadata=res://*/Sp_CodeGenerator.Model1.csdl|res://*/Sp_CodeGenerator.Model1.ssdl|res://*/Sp_CodeGenerator.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=EIRCOM;Initial Catalog=AdventureWorksLT2008R2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

我试过//*/Sp_CodeGenerator.Model...用 dll//Sp_CodeGenerator/Sp_CodeGenerator.Model.csdl等的名称替换,但它不起作用。

我还删除了 .config 文件中的所有引用,删除了 .edmx 文件和实体框架生成的模板文件并多次启动,但它不起作用。

我可以在我的目录结构中看到 edmx 文件:Model1.csdl、Model1.msl、Model1.ssdl 位于名为 edmxResourcesToEmbed 的文件夹中,它们可以在 C:\Sp_CodeGenerator\Sp_CodeGenerator\obj\x86 中找到

所以完整路径是 C:\Sp_CodeGenerator\Sp_CodeGenerator\obj\x86\Debug\edmxResourcesToEmbed

我不确定这是否是巧合,但是一旦出现问题,我还注意到,一旦我打开 .config 文件,我就会收到几条关于元素 'entityFramework' 'defaultconnectionFactory' 'type' 等缺少架构的消息。

任何关于下一步看哪里的建议,非常感谢。

MetadataException 上的完整堆栈跟踪是

  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.LoadResource()
  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReader()
  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReaders(DataSpace        spaceToGet)
   at System.Data.Metadata.Edm.MetadataArtifactLoaderComposite.CreateReaders(DataSpace  spaceToGet)
   at System.Data.Metadata.Edm.MetadataCache.EdmMetadataEntry.LoadEdmItemCollection(MetadataArtifactLoader loader)
   at System.Data.Metadata.Edm.MetadataCache.EdmItemCollectionLoader.LoadItemCollection(EdmMetadataEntry entry)
  at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
  at System.Data.Metadata.Edm.MetadataCache.GetOrCreateEdmItemCollection(String cacheKey, MetadataArtifactLoader loader, Object& entryToken)
  at System.Data.EntityClient.EntityConnection.LoadEdmItemCollection(MetadataWorkspace workspace, MetadataArtifactLoader artifactLoader)
  at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
  at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
  at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
  at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)
  at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
  at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
  at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
  at System.Data.Entity.Internal.InternalContext.Initialize()
  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.OrderBy[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)
  at Sp_CodeGenerator.SelectAll.SelectAll_Method() in    C:\Sp_CodeGenerator\Sp_CodeGenerator\Templates\dbo.SelectAll.StoredProcedure.sql.xml.cs:line 14
  at Sp_CodeGenerator.Program.Main(String[] args) in C:\Sp_CodeGenerator\Sp_CodeGenerator\Program.cs:line 15
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()
4

1 回答 1

0

我找到了解决方案 - 我只需要删除 Sp_CodeGenerator。从连接字符串中的每个 Model1 开始。不太确定为什么首先会生成这样的连接字符串?也许与我的目录结构有关?

于 2013-01-31T20:06:51.290 回答