gpt4 book ai didi

c# - 使用代码优先创建字符串索引

转载 作者:IT王子 更新时间:2023-10-29 04:01:54 24 4
gpt4 key购买 nike

我正在使用 Entity Framework 6.1 代码优先,我的领域模型如下。

class Item
{
[Index]
public string CreatedBy { set; get; }
}

当我使用 update-database 进行迁移时,出现以下错误。然而,据我研究,[Index] 应该作为 string 的注释。

Column 'CreatedBy' in table 'dbo.Items' is of a type that is invalid for use as a key column in an index.

最佳答案

通常在使用 VARCHAR(Max) 时会出现此错误,请尝试使用:

[Column(TypeName = "VARCHAR")]
[StringLength(n)]
[Index]
public string CreatedBy { set; get; }

其中 n 介于 1 和 450 之间。

关于c# - 使用代码优先创建字符串索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27687080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com