Click here to Skip to main content
16,018,394 members
Home / Discussions / C#
   

C#

 
GeneralRe: Simple Broadcast Message on Local Host Pin
jschell29-Nov-22 6:27
jschell29-Nov-22 6:27 
AnswerRe: Simple Broadcast Message on Local Host Pin
Richard Deeming28-Nov-22 23:09
mveRichard Deeming28-Nov-22 23:09 
GeneralRe: Simple Broadcast Message on Local Host Pin
CodaNV28-Nov-22 23:37
CodaNV28-Nov-22 23:37 
AnswerRe: Simple Broadcast Message on Local Host Pin
Gerry Schmitz1-Dec-22 5:27
mveGerry Schmitz1-Dec-22 5:27 
AnswerRe: Simple Broadcast Message on Local Host Pin
CodaNV11-Dec-22 16:09
CodaNV11-Dec-22 16:09 
QuestionMy winform resize when i open an OleDbConnection Pin
Le@rner27-Nov-22 18:42
Le@rner27-Nov-22 18:42 
AnswerRe: My winform resize when i open an OleDbConnection Pin
Pete O'Hanlon27-Nov-22 21:30
mvePete O'Hanlon27-Nov-22 21:30 
QuestionConcurrent Containers Pin
Richard Andrew x6424-Nov-22 14:47
professionalRichard Andrew x6424-Nov-22 14:47 
AnswerRe: Concurrent Containers Pin
Richard Deeming24-Nov-22 22:02
mveRichard Deeming24-Nov-22 22:02 
GeneralRe: Concurrent Containers Pin
Richard Andrew x6425-Nov-22 2:18
professionalRichard Andrew x6425-Nov-22 2:18 
AnswerRe: Concurrent Containers Pin
Gerry Schmitz25-Nov-22 5:10
mveGerry Schmitz25-Nov-22 5:10 
GeneralRe: Concurrent Containers Pin
Richard Andrew x6425-Nov-22 5:24
professionalRichard Andrew x6425-Nov-22 5:24 
QuestionEntity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 9:01
professionalKevin Marois24-Nov-22 9:01 
AnswerRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 9:41
mveDave Kreskowiak24-Nov-22 9:41 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 10:19
professionalKevin Marois24-Nov-22 10:19 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 14:48
mveDave Kreskowiak24-Nov-22 14:48 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 15:57
professionalKevin Marois24-Nov-22 15:57 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 16:03
mveDave Kreskowiak24-Nov-22 16:03 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois25-Nov-22 19:16
professionalKevin Marois25-Nov-22 19:16 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 5:20
mveDave Kreskowiak26-Nov-22 5:20 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 9:20
professionalKevin Marois26-Nov-22 9:20 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 9:24
mveDave Kreskowiak26-Nov-22 9:24 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 10:24
professionalKevin Marois26-Nov-22 10:24 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 11:31
mveDave Kreskowiak26-Nov-22 11:31 
This works differently from the older Entity Frameworks. The reason you're getting the login failure is because the database does not exist in SQLEXPRESS yet.

You cannot create the database just by running the code you have, as is. You first have to enable migrations in the project, then create your first migration ("InitialCreate"). Once that is done, you can add the following line your program:
C#
using (var db = new ModelContext())
{
    // Update the database to the latest migration
    db.Database.Migrate();

    // Creating a new department and save it to the database
    var newDept = new Departments();
    newDept.DepartmentId = 1;
    newDept.DepartmentName = "Development";

I highly recommend AGAINST doing this! You are far better off managing and applying migrations using the EF command line tools! You can EASILY make a mistake that will destroy a production database just by running your code at the wrong time and with the wrong connection string!

Migrations Overview - EF Core | Microsoft Learn[^]

On top of that, there's a few mistakes in your code in your initial post above. For example, every DbSet should be DbSet<type> ...
C#
public virtual DbSet<Department> Departments { get; set; }
public virtual DbSet<Employee> Employees { get; set; }

...and there are mispellings in your modelBuilder code, like
C#
entity.ToTable("Employees", "public");


GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 11:50
professionalKevin Marois26-Nov-22 11:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.