Questions tagged [db-first]

Db-First is an approach used in Entity Framework ORM which means the database tables model comes first than model.

Db-First is an approach used in Entity Framework ORM which means the database tables model comes first than model. In this approach, Entity Framework generates the model from the database tables model.

73 questions
8
votes
3 answers

How to know project is code-first or database-first?

In an existing project, how do I know if it's code-first or database-first? Project has this lines of code: public class TestDBContext : DbContext { public DbSet Players { get; set; } protected override void…
kgzdev
  • 2,770
  • 2
  • 18
  • 35
7
votes
1 answer

What is the benefit of adding .HasIndex() in your mappings, on a DBFirst scenario?

I have been searching on EF Core documentation, if adding .HasIndex() on your entities mappings would bring any benefits on a DbFirst scenario, and I couldn`t find anything. I have this 20yo DB that has all the necessary tables and indexes created,…
Tiago B
  • 1,937
  • 14
  • 34
6
votes
1 answer

How to use EF DbFirst with MySQL in .NET Core?

I try to use EF with MySQL in my project. And I add: MySql.Data.EntityFrameworkCore MySql.Data.EntityFrameworkCore.Design into my project.json but the tools section of project.json is empty. When I run: Scaffold-DbContext "myconnectionstr"…
HongyanShen
  • 1,435
  • 2
  • 14
  • 23
5
votes
1 answer

How do I pass connection string to DBContext in Entity Framework Core?

Is it possible to configure/pass connection string to the DbContext in the constructor? public partial class MyContext : DbContext { public MyContext() { } public MyContext(DbContextOptions options) : base(options) {…
mwal
  • 151
  • 3
  • 10
5
votes
1 answer

How to create one to one foreign key using FluentMigrator

I'm using this code for creating foreign key: Create.ForeignKey("FK_Table1_Table2") .FromTable("Table1").ForeignColumn("Table1_ID") .ToTable("Table2").PrimaryColumn("Table2_ID"); And as a result I have one to many relationship: public class…
A. Gladkiy
  • 3,134
  • 5
  • 38
  • 82
5
votes
1 answer

DB First with Base Entity Interface

Environment: I am working in DB First Approach. I am having 3 tables in my database. All these tables have status field to indicate the record status. This is an integer field. Scenario: I created model diagram from this table using db first…
Akhil
  • 1,918
  • 5
  • 30
  • 74
4
votes
1 answer

How to mapping enum in postgresql (db first) with ef core on .net core

I'm writing a middleware that logs the exceptions I get. I created enum values ​​on postgresql and mapped this to my log table My Log model is: public class Log { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] …
4
votes
3 answers

EF Core MySQL Database First?

I have a MySQL database sitting in Amazon Cloud (RDS). It is a tiny database with only one table. I want to use EF Core, Database First. I know that the Pomelo.EntityFrameworkCore.MySql package is popular, but I cannot see any information on how to…
J86
  • 14,345
  • 47
  • 130
  • 228
3
votes
1 answer

To add navigation property without foreign key in EF Core, DB-first migration with .NET Core Web API

I am working with an existing system and updating it to .NET Core, Web API and EF Core. The existing system has 2 tables: Parent table: Id, name, etc.. Child table: Id, ParentId, name, etc.. Though ParentId exists in the child table, there is no…
3
votes
1 answer

Difference between Scaffold-DbContext and dotnet-ef-dbcontext-scaffold

I see that there are to way how to scaffold entities and db context in Entity Framework Core 2.0. using Scaffold-DbContext using dotnet ef dbcontext scaffold Why there are two tools and what is the difference?
Liero
  • 25,216
  • 29
  • 151
  • 297
3
votes
1 answer

Using Entity Framework to save data that have foreign key constraints

I'm writing a code that reads data from files and then updates the DB (i.e deletes the entire DB and refill the tables) I have the following 4 Courses CREATE TABLE Courses ( [Id] INT IDENTITY (1, 1) NOT NULL, [Name] …
Adam
  • 464
  • 6
  • 16
2
votes
2 answers

How to add include in Generic repository pattern in Ef Core?

Net core and efcore db first approach. I have two tables. First table is SiteDetails and it contains Sitedetails related columns and it references other table countries based on primary key and foreign key relationships. Now I want to include these…
Niranjan godbole
  • 721
  • 3
  • 13
  • 28
2
votes
2 answers

Ef core query based on non primary key

Net core and EF Core DB first approach. I have one table and It has Id which is primary key and one more countryname which is non primary key. I want to query country name and I will not be passing primary key. Below is my implementation.…
Niranjan godbole
  • 721
  • 3
  • 13
  • 28
2
votes
0 answers

Updating MVC Model From Database

I am still new to EF and MVC and how they work together so excuse my ignorance. I have a SQL DB that I generated the MVC Data Model from and I have recently added some fields to a couple tables and now I need to update those changes from my SQL DB…
Alex
  • 175
  • 1
  • 3
  • 10
1
vote
1 answer

SQL surrogate table are not generated anymore by scaffolding tool after upgrade to .NET 6

I have a SQL surrogate table defined as follows: CREATE TABLE [dbo].[Blah] ( [FooID] INT NOT NULL, [ClientID] INT NOT NULL, CONSTRAINT [PK_Blah] PRIMARY KEY CLUSTERED ([FooID] ASC, [ClientID] ASC), CONSTRAINT [FK_Blah_Foo]…
GoldenAge
  • 2,918
  • 5
  • 25
  • 63
1
2 3 4 5