none
EntityFramework 6.0 compatibility with Standard .Net 2.0 library RRS feed

  • Question

  • Dear all,

    I have a project where I need to share library between other project.
    On of the project is a library EFDB which use Entity framework 6.0 and target .net 4.6 which does nothing else that getting a SQL server database model.

    Then I have an other library targeting .Net Standard 2.0, in which I have common classes that I need to share which are using the DBcontext to collect db entities from EFDB library.
    IN order to get all reference correct I start to Add Entity Frawork 6.0 into by .Net standard 2.0 library through Nuget package but then I get a warning after referencing it as below :

    Warning	NU1701	Package 'EntityFramework 6.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
    

    Is tehre anything I can do do get .net standard 2.0 cmpatible with EF6.0 ?

    How can I share my library EFDB using EF 6.0 in order to be used in my standard .net library ?

    Thnaks for your advise

    regards

    Thursday, October 11, 2018 7:57 AM

All replies

  • You need to use Microsoft.EntityFrameworkCore instead for .NET Standard 2.0 projects.

    Thursday, October 11, 2018 9:45 AM
    Answerer
  • You mean that I need to build my EFDB class by targeting the project to EntoityFramwork Core ?

    How do you do that, when you create a project library I do not see any project template refering EF core .

    Can you point out to steps to follow ?

    regards

    Friday, October 12, 2018 8:02 AM
  • Yes.

    You can find a walkthrough here.

    Friday, October 12, 2018 8:54 AM
    Answerer
  • I have seen your link but based on my initial question which is :

    "how can I share my library EFDB using EF 6.0 in order to be used in my standard .net library"

    So based on your solution path you mean that :

    1 - I need to re build my EFDB library using EF core

    2 reference my new EFDB dll inside my .net standard library

    Then my standard library can be used and share agains other project, is that correct ?

    regards 

    Monday, October 15, 2018 6:52 AM
  • 1) Add NuGet package Microsoft.EntityFrameworkCore. (You can install it on full .NET framework projects too)

    2) Change "using System.Data.Entity;" to "using Microsoft.EntityFrameworkCore;" in your project .cs and .tt files.

    3) Remove reference to Entityframework.

    4) Change the project properties of your EFDB library to ".NET Standard 2.0".

    After step 2 and 3 you may want to rebuild the project to make sure everything works as expected.

    After step 4, you can now add this project to your other .NET Standard 2.0 projects.


    Monday, October 15, 2018 7:21 AM
    Answerer