C# 实体框架:错误0194:遇到多个版本
我在SQL Server上使用实体框架工作了几年,但这个错误对我来说是新的 我用EDMX模型创建了一个库项目(DLL) 然后,我在一个小控制台应用程序中测试了它,它运行正常 最后,我尝试在需要这个DLL的实际项目中使用它,并且。。。它显然不起作用 我得到的错误是: System.Data.Entity.Core.MetadataException:未指定架构 有效。错误:错误0194:加载到 ItemCollection必须具有相同的版本。有多个版本 遇到 完整的堆栈跟踪是: System.Data.Entity.Core.MetadataException:指定的架构无效。错误: 错误0194:加载到ItemCollection中的所有构件必须具有相同的版本。遇到多个版本。 在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems中(IEnumerableC# 实体框架:错误0194:遇到多个版本,c#,.net,entity-framework,linq,metadata,C#,.net,Entity Framework,Linq,Metadata,我在SQL Server上使用实体框架工作了几年,但这个错误对我来说是新的 我用EDMX模型创建了一个库项目(DLL) 然后,我在一个小控制台应用程序中测试了它,它运行正常 最后,我尝试在需要这个DLL的实际项目中使用它,并且。。。它显然不起作用 我得到的错误是: System.Data.Entity.Core.MetadataException:未指定架构 有效。错误:错误0194:加载到 ItemCollection必须具有相同的版本。有多个版本 遇到 完整的堆栈跟踪是: System.Da
1 xmlReaders、IEnumerable1 SourceFilePath、SchemaDataModelOption、DbProviderManifest providerManifest、ItemCollection ItemCollection、Boolean throwOnError)
在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.Init中(IEnumerable1 xmlReaders,IEnumerable1文件路径,布尔throwOnError)
在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection..ctor中(IEnumerable1 xmlReaders,IEnumerable1文件路径,布尔skipInitialization)
在System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadedItemCollection(MetadataArtifactLoader)中
在System.Data.Entity.Core.Metadata.Edm.MetadataCache.c__DisplayClass5.b__0(字符串k)中
在System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey、Func
2 valueFactory)中
在System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions有效连接选项)中
在System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace()中
在System.Data.Entity.Core.Objects.ObjectContext..ctor中(EntityConnection连接、Boolean IsConnection构造函数、ObjectQueryExecutionPlanFactory ObjectQueryExecutionPlanFactory、转换器转换器、ColumnMapFactory ColumnMapFactory)
在System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()中
在System.Data.Entity.Internal.LazyInternalContext.InitializeContext()中
在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型entityType)中
在System.Data.Entity.Internal.Linq.InternalSet1.Initialize()中
在System.Data.Entity.Internal.Linq.InternalSet中
1.get\u InternalContext()
在System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider()中
在System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1源,表达式1谓词)中
在xxx:riga 261中的MailGunSender.MailManager.SendMail(字符串发件人,列表
1个收件人,列表
1个ccs,列表
1个CCN,字符串主题,字符串文本,字符串路径附件)
当然,我已经在调用者项目中安装了Entity Framework(使用Nuget),就像我在tester控制台项目中所做的那样。但这里它给了我这个错误。你知道为什么吗
我的连接字符串由以下代码管理:
public partial class Entities : DbContext
{
public Entities(string nameOrConnectionString)
: base(nameOrConnectionString)
{
}
public void Close()
{
this.Dispose();
}
public static string GetConnectionString(string server, string db, string user, string pwd)
{
string cn = "Server=" + server;
cn += ";Database=" + db;
cn += ";uid=" + user;
cn += ";Pwd=" + pwd;
var providerSB = new SqlConnectionStringBuilder(cn);
var efConnection = new EntityConnectionStringBuilder();
efConnection.Provider = "System.Data.SqlClient";
efConnection.ProviderConnectionString = providerSB.ConnectionString;
efConnection.Metadata = @"res://*";
return efConnection.ToString();
}
}
我只是偶然发现,这家伙有一个类似的问题,这与实体的唯一名称有关
他还引用了另外两篇文章
也许在您的情况下它会起作用。您的来电项目是什么?例如ASP.NET MVC、WinForms?-打开NuGet manager以检查您在所有项目上安装的实体框架包版本是否相同?是否有多个.edmx文件?您是否尝试过刷新或重新创建任何旧文件。@Scrobi我只有一个edmx文件,在dll@LukeTO'Brien调用方项目是windows服务,而测试调用方项目是控制台应用程序。是否所有项目和dll都指向同一版本的.Net?此答案需要更新,链接不是堆栈溢出中的答案,原因正是这里发生的事情。链接被删除了broken@catbadger很抱歉,在某一点上它是有效的。。。你是在寻找一个问题的答案吗?@Cat獾也许你应该提出一个新问题?