我试图将我的 MVC 3 项目移动到 MVC 4,但是当我想移动这个模型时:
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)]
属性出错。我不知道出了什么问题。有谁知道吗?!?
更新
这些是错误:
The type or namespace name 'DatabaseGeneratedAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DatabaseGenerated' could not be found (are you missing a using directive or an assembly reference?)
最佳答案
DatabaseGeneratedAttribute
位于
System.ComponentModel.DataAnnotations.Schema
.NET 4.5 中的命名空间属性
关于c# - 为什么 `DatabaseGenerated(DatabaseGeneratedOption.Identity)` 在 MVC 4 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11300883/