gpt4 book ai didi

c# - 为什么 `DatabaseGenerated(DatabaseGeneratedOption.Identity)` 在 MVC 4 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 08:33:38 34 4
gpt4 key购买 nike

我试图将我的 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/

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