Questions tagged [ef-model-first]
231 questions
41
votes
4 answers
EF Model First or Code First Approach?
I know this question has been asked numerous times before as I’ve read quite a few posts on the topic about the pros and cons etc but I still can’t decide which approach is right for me. I’m very new to web programming and come from a SQL DB Admin /…

davey
- 1,544
- 4
- 26
- 41
25
votes
10 answers
Entity Framework - "An error occurred while updating the entries. See the inner exception for details"
I have problem, I have just started learning EF Model First and Im staying in one point for some time. I got such error :
"An error occurred while updating the entries. See the inner exception for details"
I have created an easy model on diagram,…

CSharpBeginner
- 1,625
- 5
- 22
- 36
23
votes
4 answers
Model First with DbContext, Fails to initialize new DataBase
I give up.
I found this:
http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx
And thought, that's cool.
So I quickly redesigned my model to take advantage of best of two worlds.
But now my model fails at…

Łukasz Baran
- 1,229
- 3
- 24
- 47
20
votes
3 answers
How to seed data when using Model First approach?
So I am learning MVC3 and EF4.
I tried the code first method but it was too confusing for me.. I can create the classes no problem, but the hard part comes when dealing with foreign keys and the relationships between each other.
But I've gone with…

masfenix
- 7,736
- 11
- 45
- 60
15
votes
1 answer
How to do Migration when Generate database from model in Entity Framework Model First
I have an existing model and initially generated the database from this model and had populated the existing tables with some data. Now I've added a new table to the model. Is there a way to update the database from the new model without losing all…

user282807
- 905
- 3
- 13
- 26
15
votes
2 answers
Code first migrations - what connection string will it use?
Code first migrations have been working very well for me. I have a services project and a wpf project. The model is in the services project which is referenced by the wpf project. Update-database is done on the services project, but uses…

Shumii
- 4,529
- 5
- 32
- 41
14
votes
4 answers
Entity Framework 5 model first - Where is IDisposable gone?
In Entity Framework 5 model first, there seem to be some breaking changes due to the way the class files are generated (No more code generation, but T4 templates)
2 examples:
The generated context file doesn't implement IDisposable anymore
There…

Tom Deleu
- 1,177
- 1
- 15
- 29
14
votes
2 answers
Migration using model first approach in entity framework
I have setup a system where I have taken the model first approach as it made more logical sense for me. Now when even I have some changes in the model currently what I do is -
Use the Generate database from model feature of entity framework. I…

tusharmath
- 10,622
- 12
- 56
- 83
12
votes
1 answer
Entity Framework 6 Model First Migration
Desired outcome:
Use model first approach with Entity Framework and allow changes to deployed database/ model to be done automatically based on the changes in the model. Automatic schema difference script generation to allow smooth migrations.
Is…

Levent
- 193
- 1
- 9
11
votes
7 answers
Entity Framework issues - appends a "1" to my table name?
I have the following model-first (is that what it's called?) diagram that I have made. I use T4 to generate the classes.
Now, I have a problem that causes Entity Framework to somehow append a "1" to the table name of the DatabaseSupporter entity.…

Mathias Lykkegaard Lorenzen
- 15,031
- 23
- 100
- 187
10
votes
5 answers
EF 5 Model First Partial Class Custom Constructor How To?
EF has generated for me some partial classes, each with a constructor, but it says not to touch them (example below), now if I make my own secondary partial class and I want to have a constructor that automatically sets some of the fields how do I…

sprocket12
- 5,368
- 18
- 64
- 133
10
votes
2 answers
Using EF4 migration tool with model-first approach
EF migration utility seems quite nice when using code first.
Based on this blog post, I tried setting it in my project where we use model-first. When running Enable-Migrations command, I get the following error:
Creating a DbModelBuilder or writing…

Johnny5
- 6,664
- 3
- 45
- 78
8
votes
6 answers
Entity Framework Core - Foreign Key 1 (extra foreign key column)
I just upgraded to Entity Framework Core 2 and now I'm getting issues with an extra column existing and having a unique key even though it's not in my model and it's not defined anywhere else.
The index:
migrationBuilder.CreateTable(
name:…

Sellorio
- 1,806
- 1
- 16
- 32
8
votes
0 answers
Add index in EF Model First design
I like the option of doing model first design with the Entity Framework (4). However, I haven't been able to find out how to add an additional index to a table besides the primary key.
Is this possible in the visual designer? Or do you need to add…

Carvellis
- 3,992
- 2
- 34
- 66
8
votes
2 answers
Allow null foreign key GUID
I want to create a nullable foreign key with type GUID like this
[ForeignKey("CreatedBy")]
[Display(Name = "Created by")]
public Guid? CreatedById { get; set; }
public virtual User CreatedBy { get; set; }
But when I add migration and update the…

kartal
- 17,436
- 34
- 100
- 145