Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 toolbelt, with a long history of C++ QT client-server development before that.

Tying ASP.NET MVC 3 to a database using EF4 ORM is killing me.
The goals:

  1. Use database modeled by DBA. I can specify all naming conventions, but code first is not an option!
  2. Import to EDMX. This will be regularly updated using VS tools from the DBA's DB, never edited directly.
  3. Generate partial classes from EDMX, for use as model. This will regularly be updated using VS tools, never edited directly.
  4. Use 'buddy' to extend above model class with code as the Controllers/Views need.
  5. Intuitively use the resulting model, pass it to the view, retrieve posts into it for insert/save, etc...

I've seen and read so many blogs, forum posts, walkthroughs, and stack overflow posts regarding this very use case. I even tried riding the magic unicorn, followed by the latest 4.2beta1 with DbContext generators.

But can't get off the ground. I follow instructions, but just not understanding how to do anything with it. What conventions does the 'buddy' require (if any)? How do I use it? How do I get data with it? How do I write data? Every example looks different. MVC guides are always focused on the UI side. EF guides don't cover usage in the MVC.

These are basic questions, and I'm feeling like the most incompetent idiot in the WWW right now.

Is anyone out there currently using MVC3 & EF4.x in the way I describe above?

like image 295
user912639 Avatar asked Aug 25 '11 17:08

user912639


People also ask

What is DB first approach in MVC?

The Database First Approach provides an alternative to the Code First and Model First approaches to the Entity Data Model. It creates model codes (classes, properties, DbContext etc.) from the database in the project and those classes become the link between the database and controller.

How can we call stored procedure in Entity Framework database first MVC?

Open the SchoolModel. Store node and then open the Stored Procedures node. Then right-click the GetCourses stored procedure and select Add Function Import. In the Add Function Import dialog box, under Returns a Collection Of select Entities, and then select Course as the entity type returned.

What is Entityframework MVC?

Entity Framework is an open-source ORM framework for . NET applications supported by Microsoft. It enables developers to work with data using objects of domain specific classes without focusing on the underlying database tables and columns where this data is stored.


1 Answers

This video is a good starting resource. Its a video of a guy creating an app from scratch that uses entity and a sql database (though he makes the db in the video, its still good for seeing some basics in action). You can see how he pulls data from the database, displays it on the page, and saves changes back to the database.

like image 89
Kyeotic Avatar answered Oct 13 '22 00:10

Kyeotic