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
10
votes
2 answers

Can Entity Framework handle many to many relationship without an intersection object?

Using database first model: Let's say we have the classic tables Student, Course and StudentCourse (the latter obviously having FKs to Student and Course). If you import this model to EF, you will get an object generated for each of them. The…
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
10
votes
1 answer

Updating model in EF Database First project

I've inherited a project which uses Entity Framework Database First. I'm trying to work out how to update the model classes when I update the database but I can't figure it out. What I've done so far is added a column called Test to a table in the…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
9
votes
1 answer

MVC3 and EF Data first: what are the best practices?

It seems that most of the focus with MVC3 and EF4.1 is around "code first" - I can't seem to find any examples or tutorials that meet the following criteria: uses an existing SQLServer database has separate projects for web & data access (we will…
9
votes
3 answers

Entity Framework - Entity read-only property mapped to a column of related table

I have interesting problem to solve but, although common, it looks like it's not easily achievable with Entity Framework. There are two tables: Player(Id,TeamId,FirstName,LastName) Team(Id, Name, IsProfessional) Player can belong only to one team.…
Misha N.
  • 3,455
  • 1
  • 28
  • 36
9
votes
3 answers

Any Fluent API tutorials that use EF Database-First approach to explain the subject?

There are many tutorials on Fluent API, but they all explain it using Entity Framework Code-First code examples. Since I don't know Code-First, do you know of any Fluent API tutorials that would explain the subject using EF Database-First…
user702769
  • 2,435
  • 2
  • 25
  • 34
8
votes
3 answers

EF Core, database-first. How to move generic repository interface to another assembly?

I use this tutorial to create a Database model. I decided to create another assembly for abstractions such as IRepository, IFooService by reading this quote of "Programming .NET Components" by Juwal Lowy: Because interfaces can be implemented by…
8
votes
1 answer

Entity Framework DB First - Naming Navigation properties

I am using Entity framework v 6.1.1 in my application. My database has 2 tables User, Location. User table ----------- UserID HomeCityId(FK -> LocationId) CurrentCityId(FK -> LocationId) Location table LocationId LocationName Using DB First…
8
votes
2 answers

Base class/Entity in EntityFramework 5.0

I'm using Entity Framework 5 in Database First approach and I am using edmx file. Most of my entities have 6 common fields. Fields like CreatedAt, CreatedBy etc. Now, I implemented some functions as extensions that can only be applied to IQueryable…
Amila
  • 3,711
  • 3
  • 26
  • 42
8
votes
1 answer

Renaming navigation properties

Sometimes entity framework generates awful navigation property names. Using the database first approach, what is the best way to fix that? I am able to edit the t4 templates to my liking, but how would I bind these modified names to actual…
8
votes
2 answers

loosing dataAnottation when upload model from database

I have a big database existing database to comunicate with, and I'm using EF 5.0 database first, the problem I'm having is that if I create any data decoration like [stringlength(50)] on the class and then the databases is uploaded, when I "upload…
8
votes
2 answers

Unable to run EF5 migration with existing database

First, I've read these questions/answers: EF-migration message How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? Make EF4.3 Code First Migrations ignore pending migrations These all seem…
8
votes
2 answers

SimpleMembershipInitializer won't initialize

I am struggling with getting a simplemembership scenario working in my EntityFramework / MVC4 / DatabaseFirst project. I've found plenty of examples for working with code first, but nothing for DB first. The problem I'm encountering is the the…
reidLinden
  • 4,020
  • 4
  • 31
  • 46
7
votes
2 answers

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without…
7
votes
4 answers

what is advantage of CodeFirst over Database First?

I was watching some videos and tutorials for EF 4.1, and I do not understand any benefit of CodeFirst (except some if DB is very small 3-4 tables and I am lazy for creating DB first). Mostly, the best approach so far is to create Database in some…
Akash Kava
  • 39,066
  • 20
  • 121
  • 167
7
votes
2 answers

Entity Framework Core 2.2 : Disable migrations for specific entities

I'm trying to build an aspnetcore application over an existing system where the database is already created, and I'm going to add some tables over it. I've reverse engineered the database to add the existing tables as entities to my application, and…
1 2
3
48 49