how to setup EFcore database first in separate class library in ASP.NET Core MVC application?










0















I have a DB and I want to add a separate class library for entity framework to access my data but when I run scaffold command it makes a DB model in my web application.










share|improve this question
























  • what command are you running?

    – ibrahimozgon
    Nov 13 '18 at 7:13











  • Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

    – Ankit Mittal Learner
    Nov 13 '18 at 7:17












  • My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

    – Ankit Mittal Learner
    Nov 13 '18 at 7:25












  • Did you chose your data project as default project in package manager console ?

    – ibrahimozgon
    Nov 13 '18 at 7:37











  • No i dont know about that? Please tell

    – Ankit Mittal Learner
    Nov 13 '18 at 7:43
















0















I have a DB and I want to add a separate class library for entity framework to access my data but when I run scaffold command it makes a DB model in my web application.










share|improve this question
























  • what command are you running?

    – ibrahimozgon
    Nov 13 '18 at 7:13











  • Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

    – Ankit Mittal Learner
    Nov 13 '18 at 7:17












  • My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

    – Ankit Mittal Learner
    Nov 13 '18 at 7:25












  • Did you chose your data project as default project in package manager console ?

    – ibrahimozgon
    Nov 13 '18 at 7:37











  • No i dont know about that? Please tell

    – Ankit Mittal Learner
    Nov 13 '18 at 7:43














0












0








0








I have a DB and I want to add a separate class library for entity framework to access my data but when I run scaffold command it makes a DB model in my web application.










share|improve this question
















I have a DB and I want to add a separate class library for entity framework to access my data but when I run scaffold command it makes a DB model in my web application.







asp.net-core entity-framework-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 17:05









Jesse Potter

768416




768416










asked Nov 13 '18 at 7:06









Ankit Mittal LearnerAnkit Mittal Learner

54




54












  • what command are you running?

    – ibrahimozgon
    Nov 13 '18 at 7:13











  • Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

    – Ankit Mittal Learner
    Nov 13 '18 at 7:17












  • My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

    – Ankit Mittal Learner
    Nov 13 '18 at 7:25












  • Did you chose your data project as default project in package manager console ?

    – ibrahimozgon
    Nov 13 '18 at 7:37











  • No i dont know about that? Please tell

    – Ankit Mittal Learner
    Nov 13 '18 at 7:43


















  • what command are you running?

    – ibrahimozgon
    Nov 13 '18 at 7:13











  • Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

    – Ankit Mittal Learner
    Nov 13 '18 at 7:17












  • My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

    – Ankit Mittal Learner
    Nov 13 '18 at 7:25












  • Did you chose your data project as default project in package manager console ?

    – ibrahimozgon
    Nov 13 '18 at 7:37











  • No i dont know about that? Please tell

    – Ankit Mittal Learner
    Nov 13 '18 at 7:43

















what command are you running?

– ibrahimozgon
Nov 13 '18 at 7:13





what command are you running?

– ibrahimozgon
Nov 13 '18 at 7:13













Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

– Ankit Mittal Learner
Nov 13 '18 at 7:17






Scaffold-DbContext "Server=xxx;Database=xxxx;user id=xxx;password=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbContext. A folder is present in my class library name DbContext

– Ankit Mittal Learner
Nov 13 '18 at 7:17














My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

– Ankit Mittal Learner
Nov 13 '18 at 7:25






My Project Heirarcy is like this ABCProject ABCWebProject ABC.Data- Class library(Want to setup EntityFrameworkDatabase First in this Class Library)

– Ankit Mittal Learner
Nov 13 '18 at 7:25














Did you chose your data project as default project in package manager console ?

– ibrahimozgon
Nov 13 '18 at 7:37





Did you chose your data project as default project in package manager console ?

– ibrahimozgon
Nov 13 '18 at 7:37













No i dont know about that? Please tell

– Ankit Mittal Learner
Nov 13 '18 at 7:43






No i dont know about that? Please tell

– Ankit Mittal Learner
Nov 13 '18 at 7:43













1 Answer
1






active

oldest

votes


















0














You should select your Data project as default project in package manager console.



enter image description here



Be careful, you have ef core references in data.csproj



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497"/>
<PackageReference Include="System.Data.Common" Version="4.2.1" />
</ItemGroup>

</Project>


I realized that there are some errors in ClassLibrary projects. You can take a look at them:



https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#targeting-class-library-projects-is-not-supported



https://github.com/dotnet/cli/issues/8735



https://github.com/aspnet/EntityFrameworkCore/issues/10298






share|improve this answer























  • Thanks @ibrahimozgon i will run and test it.

    – Ankit Mittal Learner
    Nov 13 '18 at 7:54










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275591%2fhow-to-setup-efcore-database-first-in-separate-class-library-in-asp-net-core-mvc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You should select your Data project as default project in package manager console.



enter image description here



Be careful, you have ef core references in data.csproj



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497"/>
<PackageReference Include="System.Data.Common" Version="4.2.1" />
</ItemGroup>

</Project>


I realized that there are some errors in ClassLibrary projects. You can take a look at them:



https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#targeting-class-library-projects-is-not-supported



https://github.com/dotnet/cli/issues/8735



https://github.com/aspnet/EntityFrameworkCore/issues/10298






share|improve this answer























  • Thanks @ibrahimozgon i will run and test it.

    – Ankit Mittal Learner
    Nov 13 '18 at 7:54















0














You should select your Data project as default project in package manager console.



enter image description here



Be careful, you have ef core references in data.csproj



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497"/>
<PackageReference Include="System.Data.Common" Version="4.2.1" />
</ItemGroup>

</Project>


I realized that there are some errors in ClassLibrary projects. You can take a look at them:



https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#targeting-class-library-projects-is-not-supported



https://github.com/dotnet/cli/issues/8735



https://github.com/aspnet/EntityFrameworkCore/issues/10298






share|improve this answer























  • Thanks @ibrahimozgon i will run and test it.

    – Ankit Mittal Learner
    Nov 13 '18 at 7:54













0












0








0







You should select your Data project as default project in package manager console.



enter image description here



Be careful, you have ef core references in data.csproj



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497"/>
<PackageReference Include="System.Data.Common" Version="4.2.1" />
</ItemGroup>

</Project>


I realized that there are some errors in ClassLibrary projects. You can take a look at them:



https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#targeting-class-library-projects-is-not-supported



https://github.com/dotnet/cli/issues/8735



https://github.com/aspnet/EntityFrameworkCore/issues/10298






share|improve this answer













You should select your Data project as default project in package manager console.



enter image description here



Be careful, you have ef core references in data.csproj



<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497"/>
<PackageReference Include="System.Data.Common" Version="4.2.1" />
</ItemGroup>

</Project>


I realized that there are some errors in ClassLibrary projects. You can take a look at them:



https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#targeting-class-library-projects-is-not-supported



https://github.com/dotnet/cli/issues/8735



https://github.com/aspnet/EntityFrameworkCore/issues/10298







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 7:45









ibrahimozgonibrahimozgon

1238




1238












  • Thanks @ibrahimozgon i will run and test it.

    – Ankit Mittal Learner
    Nov 13 '18 at 7:54

















  • Thanks @ibrahimozgon i will run and test it.

    – Ankit Mittal Learner
    Nov 13 '18 at 7:54
















Thanks @ibrahimozgon i will run and test it.

– Ankit Mittal Learner
Nov 13 '18 at 7:54





Thanks @ibrahimozgon i will run and test it.

– Ankit Mittal Learner
Nov 13 '18 at 7:54

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275591%2fhow-to-setup-efcore-database-first-in-separate-class-library-in-asp-net-core-mvc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto