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
6
votes
1 answer

How to name foreign keys with database first approach

Is there a way to change the naming convention with Entity Framework? Example : I have 2 tables Planification -------------- creator_id guest_id Profile -------------- profile_id creator_id and guest_id are both foreign keys for…
Marc
  • 16,170
  • 20
  • 76
  • 119
6
votes
2 answers

Database First Validation

I have an auto-generated Entity Framework model. It was generated using a database first approach. The mid_initial column has a database defined constraint that limits the column to a maximum length of 3…
Ryan
  • 6,432
  • 7
  • 40
  • 54
5
votes
2 answers

Entity framework Core - Scaffolding enum

Context: I use Database-first approach to generate my entities with Entity Framework Core and with use of Scaffolding. Each time I change something in the database I run Scaffolding with -f parameter to rewrite generated entities. So far so good. In…
Kebechet
  • 1,461
  • 15
  • 31
5
votes
1 answer

One-to-one becomes one-to-many Entity Framework generating database-first

I'm generating Entity Framework database first (EF Designer from database). I've got two tables in Microsoft SQL Server: CREATE TABLE dbo.Person ( Pk_Person_Id INT IDENTITY PRIMARY KEY, Name VARCHAR(255), EmailId VARCHAR(255), ); CREATE…
Dmitriy Klyushin
  • 449
  • 1
  • 4
  • 22
5
votes
2 answers

EF DBFirst, table gets removed from model

Something strange is happening in my EF Database-first EDMX model. I wanted to update the model after making some changes in the DB. The update operation removed a table that did not received any changes. That table was present in the model for a…
Mik
  • 1,306
  • 1
  • 10
  • 14
5
votes
1 answer

How to singularize entities with EntityFramework core

recently I've created an ASP.NET Core (Multiplatform) project and a ClassLibrary for Managing SQL Server Database models by using VS2017. Actually we have a Database in production server and I need to generate classes by using dotnet ef dbcontext…
5
votes
1 answer

How do I create a unique constraint on a field of type string in EF 6?

First, I am new to MVC. I have a Project table which has ProjectID, ProjectNumber, and ProjectDescription fields. The ProjectId is an entityKey of type int, the ProjectNumber needs to be a unique constraint. How do I do this in entity framework…
5
votes
3 answers

EF6 database first map one to one relationship

In my database I have one-to-one relationships enforced by making a unique constraint on the foreign key table. This is correctly identified by the Sql Server Management Studio as one-to-one relation: My problem is that EF6 does not identifies this…
Copil tembel
  • 399
  • 4
  • 22
5
votes
5 answers

How can I call a SQL Stored Procedure using EntityFramework 7 and Asp.Net 5

For last couple of days I am searching for some tutorials about how to call a Stored Procedure from inside a Web API controller method using EntityFramework 7. All tutorials I came through are showing it the other way round, i.e. Code First…
5
votes
1 answer

Migrate database-first to code-first - switch from publish to migrations

We need to migrate an existing project from database-first to code-first. Each environment (DEV, TEST, PROD) has a slightly different version of the database. The differences are the changes in DEV that may not have been pushed to TEST and…
5
votes
0 answers

Entity Framework 6 - Database First - Removing column from model that should still exist in the Db

I have a database table that I have pulled into my edmx. However, a couple columns I do not want to exist in the model as they are simply for auditing purposes. The columns are "CreatedOn" and "UpdatedOn" and are simply timestamps of when the…
5
votes
2 answers

Mapping Fragments Entity Framework Error

I'm developing an ASP.NET MVC4 application (database first approach), right now I updated the model from database and then after that I got this error: Problem in mapping fragments starting at line 1106:Potential runtime violation of table…
5
votes
2 answers

How to configure entity framwork (Model First ) on microsoft azure?

I was using EntityFramwok (code First) in my application, but for some cause i have to change entityframwork approch to Database First. i have configured the project on local successfully, when published the code to microsoft azure server and tried…
R K Sharma
  • 845
  • 8
  • 23
  • 42
5
votes
1 answer

SQLite DATETIME column with Entity Framework

I have an existing SQLite database that I want to use in Entity Framework. However SQLite's weird type system means you can even create table temp(temp datetime); insert into temp values ('whatever'); The dates are stored as Unix time integers. My…
marczellm
  • 1,224
  • 2
  • 18
  • 42
5
votes
3 answers

MySql Connector with EF 6

I am having a weird issue with MySql Connector(6.8.3) and EF6. I was working on a WebApi project where I use MySql and EF6 with Database first approach. Everything worked fine[even deployed on one of the test servers] until I changed the database…
usp
  • 797
  • 3
  • 10
  • 24