简体   繁体   中英

Entity Framework for Portable Class Library

I am trying to create Repository , Entity framework for Portable Class Library , when ever I try to Nuget EntityFramework

it is Failed to add reference to 'System.ComponentModel.DataAnnotations'. Please make sure that it is in the Global Assembly Cache.

Any Idea to resolve this for EF

Compatible EF package for Portable Library

You can use fluent Api, don't use data annotations and attributes in the model class.

Example: for defining a primary key; instead of using [Key] tag, use:

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

Prior to Visual Studio Update 2 you could create a PCL project that targets .Net 4 or .Net 4.5 and Windows 8, which would allow you to install the EntityFramework nuget package. After this update you cannot target Windows 8 without Windows Phone 8.1 being automatically targeted.

This auto targeting of Windows Phone seems to prevent adding EF package to PCL that targets Windows 8.

EF7有PCL,所以如果任何一个计划使用PCL的人都可以使用早期版本的EF7或VS2014

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM