7 Replies - 792 Views - Last Post: 28 October 2019 - 02:27 PM Rate Topic: -----

#1 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 470
  • Joined: 13-September 15

Getting started using the EntityFramework

Posted 28 October 2019 - 01:38 PM

Hello

I have added the EntityFramework using this command:
dotnet add package Microsoft.EntityFrameworkCore --version 2.2.0


I tried this in my code:
using System.Data.Entity;

namespace HK.DAL {
    public class HotelDbContext : DbContext {
        //public HotelDBContext() {}
    }
}

...



And got this error running dotnet run:
DAL/HotelDbContext.cs(3,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [/home/niel/School/C#/Prak_Hotelketen/Prak_Hotelketen-EF_Start/Prak_Hotelketen-EF/Prak_Hotelketen-EF.csproj]
DAL/HotelDbContext.cs(6,35): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [/home/niel/School/C#/Prak_Hotelketen/Prak_Hotelketen-EF_Start/Prak_Hotelketen-EF/Prak_Hotelketen-EF.csproj]



This is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <AssemblyName>HK.UI.CA</AssemblyName>
        <RootNamespace>HK.UI.CA</RootNamespace>
        <LangVersion>6</LangVersion>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
      <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
    </ItemGroup>

</Project>




Is This A Good Question/Topic? 0
  • +

Replies To: Getting started using the EntityFramework

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15356
  • View blog
  • Posts: 61,557
  • Joined: 12-June 08

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 01:41 PM

What sort of project is this? ASP.NET, console, wpf?
Was This Post Helpful? 1
  • +
  • -

#3 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 470
  • Joined: 13-September 15

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 01:43 PM

View Postmodi123_1, on 28 October 2019 - 01:41 PM, said:

What sort of project is this? ASP.NET, console, wpf?


It's a C# console application.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15356
  • View blog
  • Posts: 61,557
  • Joined: 12-June 08

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 01:44 PM

.NET Core or regular ol' .NET framework?
Was This Post Helpful? 1
  • +
  • -

#5 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 470
  • Joined: 13-September 15

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 01:50 PM

View Postmodi123_1, on 28 October 2019 - 01:44 PM, said:

.NET Core or regular ol' .NET framework?


.NET core I guess:
.NET Core SDK (reflecting any global.json):
 Version:   2.2.402
 Commit:    c7f2f96116

Runtime Environment:
 OS Name:     linuxmint
 OS Version:  19.1
 OS Platform: Linux
 RID:         linuxmint.19.1-x64
 Base Path:   /usr/share/dotnet/sdk/2.2.402/

Host (useful for support):
  Version: 2.2.7
  Commit:  b1e29ae826

.NET Core SDKs installed:
  2.2.402 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download



Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7132
  • View blog
  • Posts: 24,225
  • Joined: 05-May 12

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 02:19 PM

Try running dotnet restore --force to make sure all the package references have been resolved.
Was This Post Helpful? 1
  • +
  • -

#7 smendoza88   User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 123
  • Joined: 13-July 11

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 02:19 PM

You want to use.



//using System.Data.Entity;

//this is the one you want to use.
using Microsoft.EntityFrameworkCore;

namespace HK.DAL {
    public class HotelDbContext : DbContext {
        //public HotelDBContext() {}
    }
}




This post has been edited by smendoza88: 28 October 2019 - 02:21 PM

Was This Post Helpful? 2
  • +
  • -

#8 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 470
  • Joined: 13-September 15

Re: Getting started using the EntityFramework

Posted 28 October 2019 - 02:27 PM

View Postsmendoza88, on 28 October 2019 - 02:19 PM, said:

You want to use.



//using System.Data.Entity;

//this is the one you want to use.
using Microsoft.EntityFrameworkCore;

namespace HK.DAL {
    public class HotelDbContext : DbContext {
        //public HotelDBContext() {}
    }
}





This works! Thanks mate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1