Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 7 in Xamarin.Forms

Entity Framework 7 is currently available as a Beta version and this article states that it is (will be?) possible to use Entity Framework 7 in Xamarin projects.

However, when I try to install it using NuGet:

Install-Package EntityFramework.SQLite –Pre

It will fail:

Install-Package : Could not install package 'EntityFramework.Sqlite 7.0.0-beta6'. You are trying to install this package into a 
project that targets '.NETPortable,Version=v4.5,Profile=Profile78', but the package does not contain any assembly references or 
content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package EntityFramework.SQLite –Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Is there any way to use Entity Framework in a Xamarin project or will I have to stick with sqlite-net?

Edit: As @Daniel Luberda suggested, I just tried installing Entity Framework into a project created from the Xamarin.Forms Shared Project template, but this fails with the following error:

Install-Package : Could not install package 'System.Runtime 4.0.20-beta-23109'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v5.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package EntityFramework.SQLite –Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

The same is true with the Windows Phone project and the iOS project.

like image 650
Henrik Ilgen Avatar asked Aug 25 '15 21:08

Henrik Ilgen


Video Answer


2 Answers

I just looked at the EF7 nupkg and it doesn't look like they have platform-specific compilations.

This is also confirmed by the roadmap, which says:

The November release candidate (RC1) will be a supported and production ready cross-platform release. Depending on feedback from RC1 we will ship additional release candidates as necessary.

RC1 is currently scheduled for Nov'15. Chances are you'll need to wait for that release before you can use the nuget package.

In the meanwhile... you could try building the source code from github to target PCL 78, but I suspect it won't be worth your time.

In either case if you follow good MVVM practices you should be able to build substantial parts of your app and replace the data interface as needed.

like image 107
Sten Petrov Avatar answered Oct 19 '22 03:10

Sten Petrov


This was asked to be implemented in EF 7, or now EF core 1.0, but no clear road map for it, maybe if more people ask for it in their, it will urge MS to make it:

EF 7 Xamarin.Forms support

https://github.com/aspnet/EntityFramework/issues/4269

like image 26
Reader Man San Avatar answered Oct 19 '22 04:10

Reader Man San