MySQL使用MVC3调用Context.SaveChanges时出错
-
09-12-2019 - |
题
我正在尝试获取我的mvc3应用程序来使用mysql数据库而不是sql server 2008.我在mysql中创建了关联的数据库和对象。并在Web.config文件中更新了连接字符串以引用mysql.data.mysqllient。
当我运行我的应用程序并尝试登录时,我收到错误
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
.
我有一个自定义empersionprovider,在验证过程中我有以下
using (MyContext context= new MyContext())
{
--some checks here
---
if (verificationSucceeded)
{
user.passwordFailuresSinceLastSuccess = 0;
}
else
{
int failures = user.passwordFailuresSinceLastSuccess;
if (failures != -1)
{
user.passwordFailuresSinceLastSuccess += 1;
user.lastPasswordFailureDate = DateTime.UtcNow;
}
}
context.SaveChanges(); ----THIS IS WHERE IT FALLS OVER
-- some other code here
}
.
上面的代码与SQL Server 2008完美地工作得很好,但仅使用MySQL跌倒。我怎么能解决这个问题?
我没有在底层表BTW上定义任何触发器。应用程序是MVC3,首先具有EF代码。 谢谢,
解决方案
如果有其他人有这个问题,问题是与我的问题。要克服此问题,请将以下内容添加到连接字符串
旧guids= true
例如,我的连接字符串现在看起来像它。
<add name="MyDB" connectionString="Server=localhost; Database=mydatabase; Uid=user; Pwd=mypass; Old Guids=true;" providerName="MySql.Data.MySqlClient" />
. 不隶属于 StackOverflow