MySQL Forums
Forum List  »  MySQL for Visual Studio

Re: How to start using Entity Framework 6 with MySQL databases
Posted by: Loren Yadeski
Date: December 15, 2013 07:45PM

Hello - after upgrading to EF 6 and Connector 6.8.2 RC I am receiving a "Object reference not set to an instance of an object"

I recently upgraded to Entity Framework 6 and installed the MySql 6.8.2 RC Connector as it stated there was support for EF6 Code First now.

Keep in mind, prior to the upgrade my project was functioning fine running in connector 6.7.4 and EF 5.

I made the following changes to my 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>
I also added the following references (.net 4.5 versions)

MySql.Data
MySql.Data.Entity.EF6
MySql.Web
The problem is - the moment the code calls the DBContext i receive:

Object reference not set to an instance of an object.
Again - keep in mind that everything worked prior to the upgrade, so I know its not a code issue, however, maybe I didn't setup the web.config properly?

Also - you may ask, if it worked great prior to the upgrade, why upgrade? Well, supposedly EF6 and the new MySql connector solves some bugs I was running into - so I was hoping to implement it now, while its in development and by the time it moves to production (months from now) I should be able to load in the production version of the 6.8.x connector.

Here is the stack trace in case it helps

[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

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: How to start using Entity Framework 6 with MySQL databases
17054
December 15, 2013 07:45PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.