【发布时间】:2016-03-17 22:56:52
【问题描述】:
我看过这个参考:How to use String property as primary key in Entity Framework
哪些细节与我遇到的问题基本相同。 运行更新数据库命令 导致以下错误:
'标识列 'FormId' 的数据类型必须是 int、bigint、smallint、tinyint 或小数位数或小数位数为 0、未加密且限制为不可为空的数字。'
我按照上述参考说明添加了属性,并确保没有任何 Identity 属性与我尝试使用的数据库中的该列相关联,在进行这些更改后,我仍然得到相同的确切错误消息。
我真的很想知道我错过了什么。我无法从我的搜索中发现任何其他修复。非常感谢您的帮助。
public class Form
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string FormId { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public string Url { get; set; }
}
public class UserForm
{
public string UserFormId { get; set; }
public bool IsComplete { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public Form Form { get; set; }
}
【问题讨论】:
-
你能告诉我们你的代码吗?
-
@DavidG:我添加了我正在使用的特定类,这会引发问题
-
您是否为此键定义了任何外键关系?
-
是的,我添加了引用上面Form类的类。该类是否也需要一些关联的数据属性? UserForm 有一个外键,它将引用表单的 FormId。
标签: c# sql-server entity-framework ef-code-first