MVC 4 with Entity Framework Model and Controller Designing RRS feed

  • Question

  • Hello,

    I use MVC4 and EF5 as ORM for my web application.

    My model layer has partial classes for each db objects(tables) and they have their own static methods(Forexample, Add, Delete, Change , GetOne, GetAll, etc. methods.).

    There are 4 tables in my EntityModel which names are Customer, Product, Invoice, PriceList and they have own static methods(add,delete,change,getone etc.) in different partial classses.

    According to this design example when I intend to do some copmplex db updates I have to create more than one db context instance for each different table processes(db objects). You can see below;

    In one Controller Method;

    publicActionResultDeleteFile(Customer myCustomer)



    returnJson(result, JsonRequestBehavior.AllowGet); //I know this is meanless...


    These methods go to different model partial classes so they create 4 different instance db contexts(it means 4 connections), I think it causes the slowdown problem.

    Is there any method or EF Model Design pattern that I can update all of tables in different model classes bye creating one db context object ?

    Saturday, December 22, 2012 4:16 PM