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

VS2010 Pro + SqlServer Express.

After you got into ASP.NET MVC 3 without a guide, but on the Internet (2 books to order), I can’t even get off the ground.

I get MVC myself. No problem. PHP, Ruby, and even ghastly WebForms have been running into my toolbelt, with a long history of developing the C ++ QT client server before.

Binding ASP.NET MVC 3 to a database using EF4 ORM is killing me. Objectives:

  • Use a database modeled on a DBA. I can specify all the naming conventions, but at first the code is not a parameter!
  • Import to EDMX. This will be updated regularly using VS tools from DBA DB, never edited directly.
  • Create partial classes from EDMX for use as a model. This will be updated regularly using VS tools never edited directly.
  • Use buddy to extend the model class with code as controller / view requirements.
  • Intuitively use the resulting model, transfer it to the view, restore records to it for insertion / saving, etc.

I have seen and read so many blogs , forum posts , walkthroughs and stack overflow posts about this very use case. I even tried to ride the magic of a unicorn , and then the last 4.2beta1 with DbContext generators .

But can not get off the ground. I follow the instructions, but just do not understand how to do something with it. What kind of agreement does a "buddy" require (if any)? How to use it? How do I get the data? How to write data? Each example looks different. MVC guides are always focused on the user interface side. EF guidelines do not cover use in MVC.

These are the main questions, and now I feel like the most incompetent idiot on the WWW.

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

+7
source share
3 answers

This video is a good source. His video is about a guy building an application from scratch that uses an entity and sql database (although he does db in the video, he is still good for seeing some basics in action). You can see how it retrieves data from the database, displays it on the page and saves the changes back to the database.

+2
source

The first question I would ask is why are you stuck with using EF as an ORM or even insist on an ORM? I would choose the tools to work here, especially given the limitations of the data layer.

Buddy classes were a concept invented that day when the underlying .NET ORMs did not have code options as instances of the ORM encumbered class that really didn't do very well with things, like model binding. Do not pay attention to the fact that you could not decorate them with the DataAnnotations , which was used to specify the fields. Typically, the technical requirement is to use the [MetadataType] attributes to bind your friends to your models and, perhaps, something like AutoMapper to map data to here.

Everything that was said as a guy who has several applications with a lot of friends and a lot of autopilots, you may want to think differently - this is a bit of a nightmare for maintenance. I live.

0
source

All Articles