How do I reference Entity Framework 6 from a .NET core class library in RC2?
Asked Answered
H

1

7

I have a .NET core class library from which I want to reference Entity Framework 6.1.3. Here is my project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "EntityFramework": "6.1.3" 
  },

  "frameworks": {
    "netstandard1.5": {
      "imports": "dnxcore50"
    }
  }
}

I'm getting this compilation error:

The dependency EntityFramework 6.1.3 does not support framework .NETStandard,Version=v1.5.

So I tried switching the NetStandard.Library dependency to Microsoft.NETCore.App like so:

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.NETCore.App": {
    "version": "1.0.0-rc2-3002702",
    "type": "platform"
    },
    "EntityFramework": "6.1.3"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  }
}

I'm getting a smilar compilation error as earlier:

The dependency EntityFramework 6.1.3 does not support framework .NETCoreApp,Version=v1.0

Basically, this leaves me with no option to reference Entity Framework 6.1.3 from .NET core.

I can refer EF Core from .NET core class libraries, but it is not something I wish to do right now.

Is there a solution to this?

Husband answered 27/5, 2016 at 14:5 Comment(1)
.NET core doesn't support EF 6. Either switch the framework to "net461" (or similar) or use EF Core. docs.asp.net/en/latest/data/entity-framework-6.htmlTrichromatism
D
11

Entity Framework 6.1.3 does not support .NET Core. This was part of the motivation for creating Entity Framework Core. EF 6 has deep ties to APIs in .NET Framework that may not be ported to exist in .NET Core.

You can still use EF6 with "project.json" projects but you need to target .NET Framework instead of .NET Core.

{
    "dependencies": {
        "EntityFramework": "6.1.3"
    },
    "frameworks": {
        "net461": { }
    }
}
Disestablish answered 27/5, 2016 at 17:40 Comment(2)
Thanks! I will accept this answer. Just one more question. What does "NETStandard.Library": "1.5.0-rc2-24027" under "dependencies" mean? And how is it different from "Microsoft.NETCore.App"?Husband
@Husband NETStandard.Library is for (portable) libraries, Microsoft.NETCore.App is for (.Net Core) applications.Calycine

© 2022 - 2024 — McMap. All rights reserved.