Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:30:21+00:00 2026-06-13T06:30:21+00:00

I am using EF code first in one of my mvc 3 projects. I

  • 0

I am using EF code first in one of my mvc 3 projects. I have a question about what patterns to use when passing a complex EF POCO object to and from the views.

For example, a customer object has a list of orders and each order has a list of items. The customer object will be sent to the view. The view updates the customer object and its inside objects (orders, items), then send it back the controller. The controller have EF to persist the customer object.

My questions are following:

  1. Should I serialize the EF poco object to a JSON object so I can use it inside the view?

  2. How can I re-construct the customer object when I recieve updates from view?

  3. After the customer object is reconstructed, Is it possible to save the entire object graph (customer, orders, items) in one shot?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:30:22+00:00Added an answer on June 13, 2026 at 6:30 am
    1. Should I serialize the EF poco object to a JSON object so I can use it inside the view?
      No.
    2. How can I re-construct the customer object when I recieve updates from view? Don’t. Let the default modelbinder materialize the POSTed data into a viewmodel (or editmodel), and use that data to issue commands to a lower layer.
    3. After the customer object is reconstructed, Is it possible to save the entire object graph (customer, orders, items) in one shot? It is, but you shouldn’t. Instead, deal with each update individually based on your use cases.

    Follow mojo722 and Pluc’s advice here. Don’t use EF POCO entities in your MVC layer. Use viewmodels. Here’s how it would work:

    • Controller needs data, it asks a lower layer. The lower layer gets the data and returns entities (or better yet, entity views).
    • Controller converts entities to viewmodels (AutoMapper is good for this, but you can map manually as well).
    • Controller passes viewmodels to view.
    • View sends HTTP POST data from HTML form.
    • Default model binder converts HTTP POSTed form data to a viewmodel.
    • Controller receives viewmodel data, issues a command to the lower layer.
    • Lower layer uses EF to save new entity state.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In .NET4 MVC 4 using Code First I have two classes that form a
I am using Entity Frameworks Code First. I have one entity that I need
Framework: I'm using using MVC 3 + EntityFramework 4.1 Code-First. Concept: One Legislation entity
I have created a project in MVC 3 using code first and nugget ,
I'm using Code First with EF 5. Currently I have SPs that return just
I'm using the Code First approach and have the following Model: public class Person
I'm new to .NET MVC and I'm struggling with using Code First with an
I'm using Code-first and entity framework in my .NET MVC 3 application, I created
I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
I have built up a code-first model using Entity Framework 5. The classes have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.