Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with Portable Class Library and EF Code-first?

I'm doing an Windows Phone app where I have a WebApi running in Azure.

I'm using the new "Portable Class Library" (http://msdn.microsoft.com/en-us/library/gg597391.aspx) for my "Models" project which is of cause shared between my WebApi project (this is a normale ASp.NET MVC 4 project) and my Windows Phone project.

This works great and the model (POCO) classes are serialized and deserialized just as I want.

Now I want to start storing some of my Models/POCO objects and would like to use EF Code-first for that, but that's kind of a problem as I can't add the EntityFramework assembly to my "Portable Class Library" project, and really I would not like to either as I only need a small part (the attributes) in my Models project.

So, any suggestions to how a approach this the best way?

UPDATE: Well, it seems like I can actually add the EntityFramework assembly to the project, but that doesn't really help me, as the attributes I need to use lives in System.ComponentModel.DataAnnotations which can't be used on Windows Phone. Any suggestions still?

like image 913
Mads Laumann Avatar asked Aug 11 '12 21:08

Mads Laumann


1 Answers

Don't use attributes. Use fluent API instead and create separate assembly for persistence (EF) which will reference your model assembly. Persistence assembly will be use used by your WebAPI layer.

like image 183
Ladislav Mrnka Avatar answered Feb 07 '23 01:02

Ladislav Mrnka