I\'m using Entity framework with my WEB Api project. I use code first migration.
The thing is: After making my intitial migration and trying to update database, I g
Solved it.
In your migration file, replace .Index entries by sql commands like below
CreateTable(
"dbo.Articles",
c => new
{
articleId = c.Int(nullable: false, identity: true),
title = c.String(nullable: false, unicode: false),
digest = c.String(unicode: false),
content = c.String(nullable: false, unicode: false),
imgLink = c.String(nullable: false, unicode: false),
releaseDate = c.DateTime(precision: 0),
userId = c.Int(nullable: false),
})
.PrimaryKey(t => t.articleId)
.ForeignKey("dbo.Users", t => t.userId, cascadeDelete: true)
.Index(t => t.userId); // REMOVE THIS
Add the corresponding SQL command at the bottom of your Up() method (for every index)
Sql("CREATE index `IX_userId` on `Articles` (`userId` DESC)");
The problems I add then with DataReaders are MySQL connector related. MySQL connector doesn't support multiple active connections. To handle this, if you had this in your controller
public IEnumerable<Article> GetArticles()
{
return db.Articles;
}
Now it should be
public IEnumerable<Article> GetArticles()
{
return db.Articles.ToList(); // ToList() will manage the request to work with only ONE data reader,
}
If you don't know how to convert your .Index() to SQL commands, just
update-database -verbose
and all the SQL commands will show