1 回答
TA贡献2037条经验 获得超6个赞
解决了。
在您的迁移文件中,用如下的sql命令替换.Index条目
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
在Up()方法的底部添加相应的SQL命令(对于每个索引)
Sql("CREATE index `IX_userId` on `Articles` (`userId` DESC)");
然后我为DataReaders添加的问题与MySQL连接器有关。MySQL连接器不支持多个活动连接。要处理此问题,如果您的控制器中有此命令
public IEnumerable<Article> GetArticles()
{
return db.Articles;
}
现在应该是
public IEnumerable<Article> GetArticles()
{
return db.Articles.ToList(); // ToList() will manage the request to work with only ONE data reader,
}
如果您不知道如何将.Index()转换为SQL命令,只需
update-database -verbose
并且所有的SQL命令将显示
- 1 回答
- 0 关注
- 176 浏览
添加回答
举报