Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 100.7k

How to create Controller with views ,using EF

Oct 23 2017 7:58 AM
I am facing problem in creating Controller with views ,using EF in visual studio.
 
I am following approach to speed up development of client projects,
  1. I use to create database with tables and also create their relationships
  2. Using database first approach,create the entities of all tables,
  3. Create ViewModel for each class with data annotations for validation.
  4. Now when I use to create controller using Controller with views ,using EF,its create controller and view using this viewmodel class.
  5. Problem is that this viewmodel does not exist in db,as I created this just to get data from user.so if i try to save this it gives me error that this view model does not exist.
  6. Now if I use entities that EF has created for me to create controller so that will not be good approach
  7.  I have go through different solution after googling, but my point is what is the benefit of that DB first approach if I have to go all different solution.
  8. I think in MVC 2.0 or 3.0 there is option that use can select viewmodel class and then bind it to  desired model class that is actually save data into respective table.
  9. Now there is just one option select  db context
  10. What is best approach to use  Controller with views ,using EF at maximum to speed up development.

Answers (1)