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 8026267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:26:05+00:00 2026-06-04T23:26:05+00:00

In an n-tier scenario, how is the data layer supposed to update List properties

  • 0

In an n-tier scenario, how is the data layer supposed to update List properties of an object in EF 4.3?

Let’s say we have this class:

public class Foo
{
  public int Id { get; set; }
  public string Name { get; set; }
  public List<Bar> Bars { get; set; }
}

This works well as far as saving/updating Id and Name, but the Bars property is ignored.

protected void SaveChanges(Foo foo)
{
  this.Database.Entry<Foo>(foo).State = GetState(foo);
  this.Database.SaveChanges();
}

Since the original context (that retrieved Foo) is no longer in memory, how should the data layer deal with saving updates to the Bars property? How does EF know which Bar items have been removed, which have been updated, and which have been added?

Note: I could loop through each Bar item and compare it to the original, but I’m guessing EF isn’t supposed to work that way. That seems tedious and incorrect.

  • 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-04T23:26:06+00:00Added an answer on June 4, 2026 at 11:26 pm

    How does EF know which Bar items have been removed, which have been
    updated, and which have been added?

    If you would write persistence yourselves how should it know about changes? I suppose you would choose one of two options:

    • You would query database for current state and compare it with received state to find what has changed
    • You would add some helper fields to your classes and let client tell you what has changed

    In both cases you would use information about changes to generate correct SQL.

    EF solves only the last point (SQL generation) but you are still responsible for telling it what has changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario in my 3-tier app with a Service Layer that serves
I have a three tier system, SQL Server backend, hand written data access layer,
In an N-Tier app you're supposed to have a business logic layer and a
I have a 3 tier ASP.NET MVC 3 project that has a data layer,
I have a two tier architecture based website-data layer and UI layer. I have
We have an n-tier web application that pulls data from SQL Server. Our Data
Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ
My scenario is a 3-Tier app where the data tier is a SQL Server
In my scenario, I have two types of objects. A plan and a tier
I have a data tier select method that returns a datatable. It's called from

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.