我在SQL Server的Entity Framework上工作了几年,但这个错误对我来说是新的。实体框架:错误0194:遇到多个版本
我创建了一个项目库(DLL)与EDMX模型。
然后,我从一个小控制台应用程序测试,它的工作原理。
最后,我试图在需要这个DLL和...这显然好好尝试工作,真正的项目中使用它!
我得到的错误是:
System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.
完整的堆栈跟踪是:
System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered. in System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems(IEnumerable
1 xmlReaders, IEnumerable
1 sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, Boolean throwOnError) in System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.Init(IEnumerable1 xmlReaders, IEnumerable
1 filePaths, Boolean throwOnError) in System.Data.Entity.Core.Metadata.Edm.EdmItemCollection..ctor(IEnumerable1 xmlReaders, IEnumerable
1 filePaths, Boolean skipInitialization) in System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadEdmItemCollection(MetadataArtifactLoader loader) in System.Data.Entity.Core.Metadata.Edm.MetadataCache.<>c__DisplayClass5.b__0(String k) in System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory) in System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions) in System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace() in System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory) in System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() in System.Data.Entity.Internal.LazyInternalContext.InitializeContext() in System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) in System.Data.Entity.Internal.Linq.InternalSet1.Initialize() in System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext() in System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() in System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source, Expression1 predicate) in MailGunSender.MailManager.SendMail(String from, List
1 recipients, List1 ccs, List
1 ccns, String subject, String text, String pathAttachment) in xxx:riga 261
当然,我在调用者项目(含的NuGet)安装实体框架,因为我做了测试仪控制台项目。但是这里给了我这个错误。你知道为什么吗?
我的连接字符串是通过这个代码管理:
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管理器以检查您在所有项目上安装的Entity Framework软件包版本是否相同 –
您有多个.edmx文件吗?您是否尝试刷新或重新创建任何较旧的文件。 – Scrobi
@Scrobi我只有一个EDMX文件,该dll –