Questions tagged [database-first]
171 questions
37
votes
7 answers
Adding a New Column to an Existing Table in Entity Framework
I have added a new column to a table in my database. The table is already defined in the existing Entity Framework model. I've been through most of the items here on how to do this and it still fails.
A little background, this entity model has not…

Rodney Buxton
- 411
- 1
- 4
- 6
27
votes
1 answer
Enums EF 5.0 - Database First
How can I make it so that my context objects uses the Enum feature in Entity Framework 5.0 if I am using Database First.

LazyTarget
- 879
- 1
- 14
- 30
21
votes
3 answers
Code First vs. Database First
I created an Entity Framework model based on an existing database, then generated the POCO entities from the model. The connection string in my web.config isn't Entity Framework, it's just the standard connection string (it's missing the CSDL, SSDL,…

grefly
- 1,181
- 2
- 12
- 28
16
votes
7 answers
Is it possible to prevent EntityFramework 4 from overwriting customized properties?
I am using EF 4 Database first + POCOs. Because EF has no easy way to state that incoming DateTimes are of kind UTC, I moved the property from the auto-generated file to a partial class in another file.
private DateTime _createdOn;
public…

Jason
- 4,897
- 2
- 33
- 40
15
votes
5 answers
"No executable found matching command dotnet-ef" error with EF Core database-first
As you know, the newest version of Visual Studio 2017 abandons the 'project.json' and uses .csproj instead.
I'm using the RTM version and want to generate model from an exist database, following this guide. I got an error on the last step:
The…

even
- 315
- 4
- 11
15
votes
3 answers
Is there a way to change connection string in database first?
I have several databases, the schema of them are same. When I use database-first, the connection string is specified when I create the edmx file. I want to know, is there a way to change the connection string? This is, so I can choose which database…

James
- 2,570
- 7
- 34
- 57
14
votes
2 answers
MVC DB first Fix display Name
I'm using mvc 4, with database first.
Everytime I refresh the model.edmx file, the display name attribute I added is removed. How can I the keep display name attribute between refreshes?

Eng Boon
- 363
- 1
- 3
- 10
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…

Julien N
- 3,880
- 4
- 28
- 46
10
votes
2 answers
How to prevent from DataAnnotations Attributes being deleted in DataBase First Model
I have my asp.net mvc 3 application with entity framework and i used the Database First model to set it up.
My Steps below:
1. Genarated a database with tables
2. Created ADO.NET Entity Data Model file (.edmx) and imported the tables
3. inside…

python
- 2,677
- 3
- 17
- 15
10
votes
3 answers
How to add data annotation for entities automatically created by Data-First?
If model-first, we use [MetadataType(typeof(ConceptMetadataSource))] to attach a MetadataSource file which contains all the data annotations like [HiddenInput(DisplayValue = false)] or [Display(Name = "Title")].
For…

Blaise
- 21,314
- 28
- 108
- 169
10
votes
1 answer
Entity Framework cant use the DbContext, model being created
I am using EF 4.1, and I create a normal EF edmx file.
I generate it from a DB.
When it's been generated I rightclick and select add code generation item, to generate new classes, and use the DbContext instead. I use the template DbContext…

Fore
- 5,726
- 7
- 22
- 35
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,)…

Bryan Morgan
- 126
- 6
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…

chris
- 36,094
- 53
- 157
- 237
8
votes
3 answers
It's seemingly impossible to entirely replace Entity Framework data model from database
Basically, I have a Sql Server database whose schema changes. When this happens, I have to update the EF data model. This is fine if all I did was add or delete a table: go to the designer, find "Update Model From Database..." from one of the…

Sam Rueby
- 5,914
- 6
- 36
- 52
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…

Kalyan Chakravarthy S
- 716
- 2
- 7
- 20