Questions tagged [ef-database-first]

The Database First Approach of Entity Framework provides an alternative to the Code First and Model First approaches to the Entity Data Model and it creates model codes (classes, properties, DbContext etc.) from an existing database.

The Database First Approach of Entity Framework provides an alternative to the Code First and Model First approaches to the Entity Data Model and it creates model codes (classes, properties, DbContext etc.) from an existing database.

731 questions
17
votes
4 answers

What is the best practice for multiple "Include"-s in Entity Framework?

Let's say we have four entities in data model: Categories, Books, Authors and BookPages. Also assume Categories-Books, Books-Authors and Books-BookPages relationships are one-to-many. If a category entity instance is retrieved from database -…
16
votes
2 answers

Using MVC 4 SimpleMembership with an existing database-first EF model

I am trying to use SimpleMembership in my MVC 4 for the first time and I already have an existing database and EF5 model created based on it! I searched a lot but I cant find how I could use it in my case and also to have everything under my own…
16
votes
3 answers

EntityFramework 5 - Getting value cannot be null parameter name: font error while using the designer

I'm getting a strange error while using EF 5 using a Database First approach on the designer. The error is saying 'value cannot be null parameter name: font'. I also get a big red X over the design area. I'm not exactly sure how the designer…
Mike Sage
  • 251
  • 2
  • 8
15
votes
4 answers

Invalid Column name when using savechanges() in entity framework

So here is the deal, I have changed my database schema, and changed the PK for one of my tables and I have removed everything related to the old PK (FK reference in another tables). However I have this exception when I insert a new entity using…
15
votes
2 answers

DB-First authentication confusion with ASP.NET Web API 2 + EF6

I need to create a Web API C# application for an existing MySQL database. I've managed to use Entity Framework 6 to bind every database table to a RESTful API (that allows CRUD operations). I want to implement a login/registration system (so that I…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
14
votes
2 answers

Entity Framework Core Database-First Update after initial Scaffold?

I'm playing around with Entity Framework Core and I have been working on implementing a Database-First application. The initial Scaffold-DbContext command works just fine and creates all my entities correctly, if not organized as I would like. It's…
BBlake
  • 2,388
  • 1
  • 22
  • 31
14
votes
3 answers

How to change [DisplayName] of EF generated class properties?

We know EF generates classes based on Tables we added to .edmx file. Which will not any [DisplayName] DataAnnotations for them. How can I add this [DisplayName] of generated classes without modifying them? because generated classes can be…
James123
  • 11,184
  • 66
  • 189
  • 343
13
votes
3 answers

Blazor with Database First

I'm trying to build a simple CRUD app using Blazor in Visual Studio 2019 - I have watched over 7 tutorials between YouTube, PluralSight, and Channel 9, and in all of them, they use Entity Framework Core to create the Database and Tables from within…
12
votes
1 answer

Generate Entity Framework model from Visual Studio database project

I'm using EF5 with a Database-First model. And a database project in visual Visual Studio to maintain the Sql Server database schema of an application. To update the EF model, I'm deploying the changes in a empty database... Is it possible to…
11
votes
2 answers

How to update existing model class generated by Scaffold-DbContext

Working with ASP.NET CORE EF, I have generated model classes from existing database with following command: Scaffold-DbContext "Server=myserver\mydb;Database=mydb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir…
M_Idrees
  • 2,080
  • 2
  • 23
  • 53
11
votes
2 answers

EntityFramework refuses to forget old columns

I'm using EntityFramework 6.1.3, database-first. I am currently wishing I had chosen code-first... I have a database with some tables. I've previously built my edmx off of these tables. Then I changed the type of a few columns and added a few…
Nacht
  • 3,342
  • 4
  • 26
  • 41
11
votes
1 answer

Change entities and properties names in Database First

I'm starting a new application that must use an existing database that use some naming conventions that are really annoying in .net (table names start with several trigrams that specify the business domain of the table, column names start with the…
10
votes
1 answer

Entity Framework - DB-First - Composite Foreign Keys

I have a database that has a table with a 2-column primary composite key (one int, one bigint.) I have two tables that have a composite foreign key, referencing the first table's composite primary key. The relationships are (as far as I know,)…
10
votes
1 answer

What binds ApplicationUser to the aspnetusers table in Database First?

I have a database-first EDMX model in a separate library (e.g. Common.Feedback.Data), that includes the AspNetUser table and its related Identity Framework tables (pulled from another existing, working, database/application). I have updated the…
10
votes
2 answers

Entity Framework Database First - Composite Foreign Keys

I have a database that contains a couple of composite foreign keys. For example, here is the generation script for the foreign key: ALTER TABLE [dbo].[WorkingRosters] WITH NOCHECK ADD CONSTRAINT [FK_WorkingRoster_ShiftLeaveCode] FOREIGN…
1
2
3
48 49