0

I use MVC 4 Internet Application with VS 2012 and Entity (5.0) Framework Database First..

I created my database with relationships..

I create ADO.NET Entity Data Model.. And I can see all relationships (one-to-one, one-to-many, many-to-many)..

I want to create my controller and views with "mvc controller with read/write actions and views using entity framework".. There is no problem with One-to-Many and One-to-One..

How about Many-to-Many??

tereško
  • 58,060
  • 25
  • 98
  • 150
yusuf
  • 1,233
  • 1
  • 15
  • 29

2 Answers2

1

You can reverse engineer your db.context from your database (if you have entity framework nuget package installed) by right clicking on your project->entity framework-> reverse engineer from code first.

To enable this option first install - Entity Framework Power Tools

Setup is fairly simple but a guide like this might help -> Setup Tutorial

This will automatically setup your database context maps as they are in your database. The table maps created, contain the relationship code.

I have a many-to-many relationship in a table in my app and this works fine.

Whiplash450
  • 943
  • 2
  • 12
  • 22
  • I want to work with Database First.. Yes, The Entity Framework has been installed already.. but I can't find reverse engineer.. – yusuf Feb 13 '13 at 14:12
  • In the solution explorer (on the righthand side in Visual Studio 2012) right click your project. If you do not see a sub-menu called 'Entity Framework' then you do not have it installed. This can also be checked from your installed packages in the 'Manage Nuget packages' from the Project tab at the top of VisStudio. – Whiplash450 Feb 13 '13 at 14:33
  • I am sure Entity Framework installed.. [1]: http://i.stack.imgur.com/3O5ct.png But there is no sub-menu called "Entity Framework" when i right click my project.. [2]: http://i.stack.imgur.com/fCcWX.png – yusuf Feb 13 '13 at 15:16
  • 1
    Ok you're looking for this option after right clicking on your project: http://img560.imageshack.us/img560/5571/reversee.png [2]If you can't see this option then you need to install the Entity Framework Power Tools (http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d) – Whiplash450 Feb 13 '13 at 15:23
  • This is a great tutorial on how to set it all up: http://romiller.com/2012/05/09/customizing-reverse-engineer-code-first-in-the-ef-power-tools/ – Whiplash450 Feb 13 '13 at 15:28
0

All problems, which are something like that, are about the ViewModels..

http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3fundamentals_topic7.aspx

yusuf
  • 1,233
  • 1
  • 15
  • 29