Entity Framework for Portable Class Library

放肆的年华 提交于 2019-12-21 11:01:21

问题


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


回答1:


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



回答2:


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.




回答3:


EF7 has PCL , so if any one planning to use PCL can use early version of EF7 or VS2014



来源:https://stackoverflow.com/questions/22879578/entity-framework-for-portable-class-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!