c# - EntityFramework and saving single entities -
i'm trying wrap head around entityframework , how it's supposed work. developing desktop application in c#.net using entityframework 4. application heavy on tabs. there main window , user in application done in separate tab.
so example, application have orders , customers.
lets user starts creating new order , halfway through decides edit customer (both displayed in separate tabs). when try save customer (in code i'd calling objectcontext.savechanges()) entityframework try save order still being worked on user. don't want , want save customer.
i think missing crucial in understanding of how entityframework supposed used because doesn't seem ever work in application allows users work on multiple entities @ time.
you can use multiple entity objects, since can assign 1 model per view, tabbed ui still single form, hides tabbed elements until event makes them visible. so, @ top of view calls model, you'll familiar this:
@model web.project.name.models.viewmodel however, can use partial views on each of tabs invoke model want user interact with, because partial views can have own models. in way, each tab becomes own form. main page(sans layout view):
@model web.project.name.models @{viewbag.title = "orders & customers";} ... <div class="tab-1"> @html.partial("_orderspartial") </div> <div class="tab-2"> @html.partial("_customerspartial") </div> those partials you're loading each have own model:
_orderspartial.cshtml:
@model web.project.name.models.ordersviewmodel @{viewbag.title = "orders & customers";} ... in case, user interaction each tab , partial view handle each tab own form, is. it's important note don't need more one entity objects create different models. can use entity framework create multiple models same db.
Comments
Post a Comment