为什么`DatabaseGenerated(DatabaseGeneratedOption.Identity)`在MVC 4中不起作用 [英] Why `DatabaseGenerated(DatabaseGeneratedOption.Identity)` doesn't work in MVC 4
问题描述
我试图将我的MVC 3项目移动到MVC 4,但是当我想移动该模型时:
I was trying to move my MVC 3 project to MVC 4 but when I wanted to move this model:
public class Link
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
[DisplayName("Shorted URL")]
public string SURL { get; set; }
[DisplayName("General Link")]
public string OriginalURL { get; set; }
[DisplayName("Click Count")]
public int ClickCount { get; set; }
}
public class LinkDBContext : DbContext
{
public DbSet<Link> Links { get; set; }
}
[System.ComponentModel。 DataAnnotations。(DatabaseGeneratedOption.Identity)]
属性。我不知道出什么问题了。有人知道吗?!?
I got error with [System.ComponentModel.DataAnnotations.(DatabaseGeneratedOption.Identity)]
attribute. I don't know what's the problem. Does anyone know?!?
更新
这些是错误:
找不到
的类型或名称空间名称'DatabaseGeneratedAttribute'(您是否缺少using指令或程序集引用?)
The type or namespace name 'DatabaseGeneratedAttribute' could not be found (are you missing a using directive or an assembly reference?)
找不到类型或名称空间名称 DatabaseGenerated(
您是否缺少using指令或程序集引用?)
The type or namespace name 'DatabaseGenerated' could not be found (are you missing a using directive or an assembly reference?)
推荐答案
DatabaseGeneratedAttribute
在
<$中.NET 4.5中的c $ c> System.ComponentModel.DataAnnotations.Schema 命名空间属性
这篇关于为什么`DatabaseGenerated(DatabaseGeneratedOption.Identity)`在MVC 4中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!