Entity Framework 6 with Mysql and NullReferenceException

asp.net c# entity-framework entity-framework-6 mysql

Question

I keep getting a NullReferenceException problem when I try to insert the same data.

In the community forums for MySQL, Asp.net, and Stackoverflow, I have read a ton of posts. I was unable to come up with a real answer to this issue. There are several answers available for that. However, someone fixed my problem and those of other people. I discovered some bug reports referencing that issue. However, each report should be resolved. Internet Connector 6.8.3. I believe I am missing a relatively easy step in EF with Mysql, but I am unable to identify my errors.

Model Code:

using (prodEntities myEntity = new prodEntities ())
{
  userloginlog log = new userloginlog();
  log.UserRef = pUserID;
  log.Success = pSuccess;
  log.IpNo = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
  log.BrowserInfo = browserInfo;
  log.LoginTime = GeneralHelperC.getCompanyDateTime();
  myEntity.userloginlog.Add(log);
  myEntity.SaveChanges();
}

Table:

CREATE TABLE `userloginlog` (
  `RID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `UserRef` bigint(20) unsigned NOT NULL,
  `LoginTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `IpNo` varchar(15) DEFAULT NULL,
  `Success` tinyint(4) NOT NULL,
  `BrowserInfo` varchar(1000) DEFAULT NULL,
  PRIMARY KEY (`RID`),
  KEY `userLoginLog_Staff_Key` (`UserRef`),
  CONSTRAINT `UserLoginLog_User_Key` FOREIGN KEY (`UserRef`) REFERENCES `users` (`RID`)
) ENGINE=InnoDB AUTO_INCREMENT=16903 DEFAULT CHARSET=utf8;

Exception:

   at MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
   at MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
   at MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
   at MySql.Data.Entity.SqlFragment.ToString()
   at MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
   at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(Dictionary`2 identifierValues)
   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__d()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClassb.<SaveChangesInternal>b__8()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()

Added to my computer:

  • 5.6CE MySql Server
  • 6.8.3 MySQL Connector
  • V. Studio. 2013

DLLs in the project that have been refenced (all installed via nuget)

  • MySql.Data.dll (6.8.3)
  • MySql.Data.Entity.dll (6.7.5)
  • MySql.Data.Entities.dll (6.8.3.0)
  • MySql.Web.dll (6.8.3)
  • EntityFramework.dll (6.1.1)

Asp.Net Webform is the project that is currently running. 4.0 Net Framework

I appreciate you.

1
2
7/3/2014 4:54:31 AM

Popular Answer

We had a comparable problem. We lacked an ID field, but our primary key was a timestamp. The answer was to create an ID and make it the primary key.

1
10/11/2015 11:00:34 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow