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?)
DatabaseGeneratedAttribute
is in the
System.ComponentModel.DataAnnotations.Schema
namespace attribute in .NET 4.5
If you want to use this attribute in .net 4 you can use Prerelease version of EntityFramework 6 (or even Nightly Builds) to do this, in Manage NuGet Pakages
window, from the drop-down on top of the window, select Include Prerelease
.
To update to Nightly Builds, in Pakage Manager Settings
add this Package Source:
http://www.myget.org/F/aspnetwebstacknightly/
For a complete guide, see EF on GitHub.
You need - in some cases - to change the framework from 4.5 or less to 4.5.1 and then install Entity Framework 6 + and it will be found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With