Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityFramework Commands in ASP.Net 5 Class Library Package?

I am trying to develop my first ASP.Net web application and in my solution I have two projects. A Web Application and Class Library (Package). When I build the ASP.Net 4.5 version of this application I put my Entity Framework 6 entities into a class library, so I am doing that in the ASP.Net 5 version. The problem is when I install EntityFramework.Commands to the class library I get the error:

The dependency EntityFramework.Command 7.0.0-rc1-final in Project DBEntities does not support framework .NetPlatform, Version = 5.4

My understanding from this SO question is that dotnet5.4 is the new .Net 5 which is supposed to be supported by EF7.

Here is my project.json file:

{
  "version": "1.0.0-*",
  "description": "FFInfo.DAL Class Library",
  "authors": [ "Mathew" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-23516",
                "System.Collections": "4.0.11-beta-23516",
                "System.Linq": "4.0.1-beta-23516",
                "System.Runtime": "4.0.21-beta-23516",
                "System.Threading": "4.0.11-beta-23516"
            }
        }
    },
    "dependencies": {
        "EntityFramework.Commands": "7.0.0-rc1-final",
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
    }
}

Did I install the wrong package, is EF7 changed so much that I am building out the class wrong, or am I missing something in my json file?

EDIT: New project.json file based off suggestions

{
    "version": "1.0.0-*",
    "description": "FFInfo.DAL Class Library",
    "authors": [ "Mathew" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
                "Microsoft.Dnx.Runtime": "1.0.0-*",
                "Microsoft.Extensions.CommandLineUtils.Sources": {
                    "version": "1.0.0-*",
                    "type": "build"
                },
                "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
                "System.Console": "4.0.0-*",
                "System.IO.FileSystem": "4.0.1-*"
            }
        },
        "netcore50": {
            "bin": {
                "assembly": "lib\\netcore50\\_._"
            }
        },
        "dependencies": {
            "EntityFramework.Commands": "7.0.0-rc1-final",
            "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
        }
    }
}
like image 675
Matthew Verstraete Avatar asked Dec 19 '15 12:12

Matthew Verstraete


People also ask

What is Entity Framework in asp net?

Entity Framework (EF) is an object-relational mapper that enables . NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. Get it: Add this to your project and start taking advantage of this powerful O/RM.

Can we use Entity Framework in class library?

Net Core Entity Framework Code First Approach Using Class Library Project. With reference to Getting Started with EF Core, I am using the MSSQL server. You can follow the above Microsoft Document to create project using either CLI or Visual Studio.

How do I run migration in Package Manager console?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).


1 Answers

I suppose that the reason of your problem have pure technical nature. The announcement declares renaming of dnx451 to net451 and dnxcore50 to dotnet5.4, but one recommend to use such renaming only for class libraries (which you publich on NuGet for example to share with other). If I understand you correctly, that you develop application which uses class libraries and thus you should use dnxcore50 instead of dotnet5.4. Thus you need just rename the string "dotnet5.4" to the string "dnxcore50" in the fileproject.json` to fix the problem.

Independent from the above recommendation I want to add my understanding of your problem, why you get the error about EntityFramework.Command 7.0.0-rc1-final.

I understand the renaming of frameworks as the step in direction to future changes which plan Microsoft. On the other side all names of frameworks will be interpreted just as different names. I suggest you to compare the information about the dependencies displayed on the page https://www.nuget.org/packages/EntityFramework.Commands/7.0.0-rc1-final from the corresponding information from https://www.nuget.org/packages/EntityFramework.MicrosoftSqlServer/7.0.0-rc1-final. The dependencies of EntityFramework.MicrosoftSqlServer (which have no problems with the usage of dotnet5.4) looks like on the picture

enter image description here

I marked read the part responsible for dotnet5.4. On the other side the dependencies of EntityFramework.Commands looks like on the picture below:

enter image description here

where there are no ".NETPlatform 5.4" section which corresponds the new name dotnet5.4.

I suppose that it's a bug in the part of project.json of EntityFramework.Commands:

"netcore50": {
  "bin": {
    "assembly": "lib\\netcore50\\_._"
  }
}

I suppose that one have to change netcore50 to dotnet5.4 in the lines to support new framework name dotnet5.4 correctly. One chould replace the content of "netcore50" to the copy from dnxcore50 (see the lines):

"dotnet5.4": {
  "dependencies": {
    "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
    "Microsoft.Dnx.Runtime": "1.0.0-*",
    "Microsoft.Extensions.CommandLineUtils.Sources": {
      "version": "1.0.0-*",
      "type": "build"
    },
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
    "System.Console": "4.0.0-*",
    "System.IO.FileSystem": "4.0.1-*"
  }
}

Probably one should event increase some version numbers of the dlls referenced above, but you still will be not able to use EntityFramework.Commands under "dotnet5.4" till the new fixed version will be published.

UPDATED: I posed the issue to the EntityFramework developer team. I'll include the response from Microsoft on the issue after I'll get it.

like image 76
Oleg Avatar answered Oct 04 '22 03:10

Oleg