Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 770
ineffable p Avatar asked Apr 05 '14 10:04

ineffable p


1 Answers

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);
}
like image 141
A-Sharabiani Avatar answered Sep 23 '22 06:09

A-Sharabiani