Entity Framework for Portable Class Library

c# entity-framework silverlight windows-8 windows-phone-8

Question

Every time I try to install Nuget EntityFramework, I am unable to construct a repository or an entity framework for a portable class library.

Adding a reference to "System.ComponentModel.DataAnnotations" has failed. Make sure it is in the Global Assembly Cache, please.

Any suggestions to fix this for EF?

EF package compatible with Portable Library

1
7
4/5/2014 10:36:44 AM

Accepted Answer

If somebody is wanting to utilize PCL, they can use an early version of EF7 or VS2014 because EF7 has PCL.

3
11/12/2014 9:41:43 AM

Popular Answer

You can use fluent API, but you shouldn't use attributes and data annotations in the model class.

Using this example, let's define a primary key instead of[Key] label, use:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<Record>().HasKey<int>(s => s.ID);
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow