c# – EF:空间/全文/散列索引和显式索引顺序的使用不正确
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – EF:空间/全文/散列索引和显式索引顺序的使用不正确,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2891字,纯文字阅读大概需要5分钟。
内容图文
我在我的WEB Api项目中使用Entity框架.
我使用代码首次迁移.
问题是:在进行我的初始迁移并尝试更新数据库之后,我收到此错误
Incorrect usage of spatial/fulltext/hash index and explicit index order
这是由更新数据库中的此SQL命令引起的:
create table `Articles`
(
`articleId` int not null auto_increment ,
`title` longtext not null ,
`digest` longtext,
`content` longtext not null ,
`imgLink` longtext not null ,
`releaseDate` datetime,
`userId` int not null ,
primary key ( `articleId`)
) engine=InnoDb auto_increment=0
CREATE index `IX_userId` on `Articles` (`userId` DESC) using HASH
在迁移中从此代码生成SQL命令:
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);
看起来像DESC和HASH上的索引创建导致此错误.
有关如何更改生成的sql索引创建的任何想法,所以它与简单的索引一起使用?或者只是简单地绕过这个错误,以便我的更新数据库可以通过?谢谢 !
编辑:添加文章类
public class Article
{
public Article()
{
this.comments = new HashSet<Comment>();
}
[Key]
public int articleId { get; set; }
[Required]
public string title { get; set; }
public string digest { get; set; }
[Required]
public string content { get; set; }
[Required]
public string imgLink { get; set; }
public DateTime? releaseDate { get; set; }
// Clé étrangère (table User)
public int userId { get; set; }
// Auteur de l'article
public virtual User user { get; set; }
// Commentaires
public virtual ICollection<Comment> comments { get; set; }
}
我将在迁移文件中的每个.Index()的输出中添加DESC HASH on index
解决方法:
解决了它.
在迁移文件中,用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)");
我在DataReader中添加的问题与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命令
内容总结
以上是互联网集市为您收集整理的c# – EF:空间/全文/散列索引和显式索引顺序的使用不正确全部内容,希望文章能够帮你解决c# – EF:空间/全文/散列索引和显式索引顺序的使用不正确所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。