Skip to content

Why Context does not have DbSet<>? #1

@Ar33ss

Description

@Ar33ss

I am trying to learn the architecture but cannot understand why Context does not have DbSet<> tables. For example:

public DbSet <Department> Departments {get;set;}
public DbSet <User> Users {get;set;}

When running migrations, tables are not creating in the database.

Even adding them to DbContext this error shows up:

The entity type 'BaseDomainEvent' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.

Even ignoring DbSet<> running the API project when hitting Users shows this error:

System.InvalidOperationException: Cannot create a DbSet for 'User' because this type is not included in the model for the context.

I did a migration in VSCode.

dotnet ef migrations add initialcreation1 -s ../API/API.csproj
dotnet ef database update -s ../API/API.csproj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions