【发布时间】:2014-01-03 07:46:29
【问题描述】:
我最近升级到 Entity Framework 6 并安装了 MySql 6.8.2 RC 连接器,因为它表示现在支持 EF6 Code First。
请记住,在升级之前,我的项目在连接器 6.7.4 和 EF 5 中运行良好。
我对 web.config 进行了以下更改
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
<connectionStrings>
<add providerName="MySql.Data.MySqlClient" name="dbcontext" connectionString="Server=localhost; Database=db; Uid=un; Pwd=pw;Convert Zero Datetime=True" />
</connectionStrings>
我还添加了以下引用(.net 4.5 版本)
- MySql.Data
- MySql.Data.Entity.EF6
- MySql.Web
问题是 - 代码调用我收到的 DBContext 的那一刻:
Object reference not set to an instance of an object.
再次提醒 - 请记住,在升级之前一切正常,所以我知道这不是代码问题,但是,也许我没有正确设置 web.config?
另外 - 您可能会问,如果它在升级之前运行良好,为什么要升级?好吧,据说 EF6 和新的 MySql 连接器解决了我遇到的一些错误 - 所以我希望现在实现它,而它正在开发中,到它投入生产时(几个月后)我应该能够加载6.8.x 连接器的生产版本。
这是堆栈跟踪以防万一
[NullReferenceException: Object reference not set to an instance of an object.]
MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +85
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +332
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +67
System.Data.Entity.Infrastructure.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple`3 k) +63
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +260
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +89
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +79
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +143
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +171
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +594
System.Data.Entity.Internal.InternalContext.Initialize() +31
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +138
System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path) +41
System.Data.Entity.Infrastructure.DbQuery`1.Include(String path) +142
[edited].Global.Application_BeginRequest(Object sender, EventArgs e) in c:\edited\Global.asax.cs:47
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
【问题讨论】:
-
您不打算在项目支持网站上将此报告为问题/错误吗?因为它是 RC,所以它是一个测试版。
-
我不确定这是否是一个错误,或者是否有新的/差异方式来设置它 - 但是我也确实在 mysql 论坛上发布了这个。所以如果我在那里得到答案,我也会在这里更新它
-
mysql论坛中问题的链接怎么样?
-
@99823 您找到导致此问题的原因了吗?
-
我将web项目设置为启动项目,然后就成功了。
标签: c# mysql entity-framework ef-code-first