Questions tagged [database-first]

171 questions
8
votes
4 answers

The entity type [Name] is not part of the model for the current context

I create a model using EF and generated its context using DbContext 5.X generator. Now I renamed class name of one of my entities. Now when I run my code I get "The entity type Student2 is not part of the model for the current context." error. var…
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
7
votes
3 answers

MVC 3, Entity Framework 4.x, Database First, Desperation

VS2010 Pro + SqlServer Express. Having been dropped into ASP.NET MVC 3 with no guidance but the web (2 books on order), I can't even get off the ground. The MVC itself I get. Not a problem. PHP, Ruby, and even ghastly WebForms firmly tucked into my…
7
votes
2 answers

How to get database information with entityframework database first?

When I use Entity Framework codefirst I can use the following code to get my database connection string: var db = new dbContext(); Console.Writeline(db.Database.Connection.ConnectionString); But when I do database first, Database is not available.…
7
votes
7 answers

Get parent department node in Entity Framework

I have a SQL table like this: DepartmentID is parent of department. I've build a tree by this table(in ASP.net (C#) project): Records in tree above is: I need to get parents in this tree. I can do it in SQL Server like this(for Example id=2, id…
Ali Soltani
  • 9,589
  • 5
  • 30
  • 55
6
votes
2 answers

Adding foreign key in visual studio 2012

I'm developing my first MVC project in Visual Studio 2012. Because i prefer "database first" approach i've started to design database. The question is: Why when i want to add foreign key i have all key properties disabled to edit (left): I can only…
Kamil Będkowski
  • 1,092
  • 4
  • 16
  • 36
6
votes
1 answer

Database first Entity Framework mapping unique foreign keys as one to many

I have a table in Microsoft SQL Server 2008 R2 called Page with a primary key called ID. I have another table called Navigation with a column PageID. PageID is a unique foreign key reference to the ID column of Page. This creates a one to one…
Michael J. Gray
  • 9,784
  • 6
  • 38
  • 67
5
votes
0 answers

Entity Framework, Database First, Class File Not Created

I have a pretty complex EF model created from an MS SQL database. (I'm using EF 6.1.0.) I added a table to the database and did "Update Model from Database." Unfortunately, something went wrong, and while lots of XML was generated in the .edmx file…
Jim S
  • 1,069
  • 3
  • 10
  • 17
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
1 answer

Entity Framework DB First: Convert Associative Table to Navigation Properties

I am using Entity Framework Database First, but I would like to replicate the following behavior from the Code First paradigm: In Entity Framework Code First, you can do something along these lines: public class Thing { public int ID { get; set;…
5
votes
2 answers

EF DB-first mapping mess

I have a frustrating situation owing to this little quirk of EF. Here's a simple demo of the behavior. First the DB schema: As you see, RestrictedProduct is a special case of product, which I'm intending to make a subclass of Product with some…
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
5
votes
1 answer

Add Function Import not available for function

I've added a function in my database and I wanted it to be callable in my code. For stored procedures I've right clicked on the SP and selected Add Function Import in Model Browser to achieve this, but this option is not available for my function. …
4
votes
6 answers

Why does Database First EF skip mapping some tables?

I'm using Entity Framework 4 and with a Database First binding, and EF is not generating the entities for a few of my tables. I'm not getting any errors, and no matter how many times I select the tables to generate from the "Update Model from…
John Kaster
  • 2,509
  • 1
  • 33
  • 40
4
votes
1 answer

Best way to approach tying in Entity Framework 4 ("Database First") and MVC3

I am a relative newcomer for C#.Net (.net 4), EF4, Winforms, and MVC3. I had laid out a database in SQL Server in the process of developing a Winforms "backend" for a task I have been assigned. I setup a single Solution and created a .edmx from the…
4
votes
1 answer

Separating entity framework poco and objectcontext

so far i was creating a classLibrary project and inserting new Ado.net Entity data model and genareting from exixting database. Class and object class codes are creating automatically. this is not important for me. but i want to do this and separate…
barteloma
  • 6,403
  • 14
  • 79
  • 173
4
votes
1 answer

ASP.NET WebAPI Identity Entity Framework Database-First model

I would like to ask you how can I implement DB First model in ASP.NET Identity Scheme. When I create a WebAPI project with individual user authentication I can see code-first model with some implementation in it. I am trying to solve this and I was…
1
2
3
11 12