实体框架:错误0194:遇到多个版本

时间:2017-05-10 09:10:43

标签: c# .net entity-framework linq metadata

我在SQL Server上使用Entity Framework工作了几年,但这个错误对我来说是新的。

我使用EDMX模型创建了一个库项目(DLL)。

然后,我从一个小的控制台应用程序测试它,它可以工作。

最后,我试图在需要这个DLL的真实项目中使用它......显然它很难工作!!

我得到的错误是:

  

System.Data.Entity.Core.MetadataException:指定的架构不是   有效。错误:错误0194:所有工件加载到   ItemCollection必须具有相同的版本。多个版本   遇到。

完整的stackTrace是:

  

System.Data.Entity.Core.MetadataException:指定的架构无效。错误:   错误0194:加载到ItemCollection中的所有工件必须具有相同的版本。遇到了多个版本。      在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems(IEnumerable 1 xmlReaders, IEnumerable 1 sourceFilePaths,SchemaDataModelOption dataModelOption,DbProviderManifest providerManifest,ItemCollection itemCollection,Boolean throwOnError)      在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.Init中(IEnumerable 1 xmlReaders, IEnumerable 1 filePaths,Boolean throwOnError)      在System.Data.Entity.Core.Metadata.Edm.EdmItemCollection..ctor中(IEnumerable 1 xmlReaders, IEnumerable 1 filePaths,Boolean skipInitialization)      在System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadEdmItemCollection(MetadataArtifactLoader loader)中      在System.Data.Entity.Core.Metadata.Edm.MetadataCache中。<> c__DisplayClass5.b__0(String k)      在System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory)      在System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions)中      在System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace()中      在System.Data.Entity.Core.Objects.ObjectContext..ctor中(EntityConnection连接,Boolean isConnectionConstructor,ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory,Translator translator,ColumnMapFactory columnMapFactory)      在System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()中      在System.Data.Entity.Internal.LazyInternalContext.InitializeContext()中      在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)中      在System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() in System.Data.Entity.Internal.Linq.InternalSet中1.get_InternalContext()      在System.x中的System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() in System.Linq.Queryable.FirstOrDefault[TSource](IQueryable 1个源,表达式1 predicate) in MailGunSender.MailManager.SendMail(String from, List 1个收件人,列表1 ccs, List 1个ccns,字符串主题,字符串文本,字符串pathAttachment):riga 261

当然,我已经在调用者项目中安装了Entity Framework(使用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();
    }
}

1 个答案:

答案 0 :(得分:-1)

我偶然发现了this article,这个家伙遇到了类似的问题,而且它与 Entites的唯一名称有关。
他还引用了另外两篇文章。

也许它适用于你的情况。

相关问题