11

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; }
}

I got error with [System.ComponentModel.DataAnnotations.(DatabaseGeneratedOption.Identity)] attribute. I don't know what's the problem. Does anyone know?!?

Update

These are the errors:

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?)

4

3 回答 3

27

DatabaseGeneratedAttributeSystem.ComponentModel.DataAnnotations.Schema位于 .NET 4.5的 命名空间属性中

于 2012-07-02T21:35:00.933 回答
2

如果您想在 .net 4 中使用此属性,您可以使用 EntityFramework 6 的预发布版本(甚至是 Nightly Builds)来执行此操作,在Manage NuGet Pakages窗口中,从窗口顶部的下拉列表中选择Include Prerelease.

要更新到 Nightly Builds,请Pakage Manager Settings添加此包源:

http://www.myget.org/F/aspnetwebstacknightly/

如需完整指南,请参阅GitHub 上的 EF

于 2012-12-10T06:11:04.023 回答
1

您需要 - 在某些情况下 - 将框架从 4.5 或更低版本更改为 4.5.1,然后安装 Entity Framework 6 +,它会被发现

于 2015-11-02T23:20:39.720 回答