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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:07:27+00:00 2026-05-18T04:07:27+00:00

HI, Wit linq i populate a generic list in DAL. then in UI layer

  • 0

HI,
Wit linq i populate a generic list in DAL. then in UI layer the user removes and updates items from the list. Is it possible for LINQ to keep track of the changes without having to write code to check which items have been removed and deleting them/adding new items and updating others etc. it seems that this is not possible when using datacontext which popluates the list and seperate datacontext which is responsible fo SubmitChanges. Any help appreciated.

thanks
Niall

  • 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-05-18T04:07:27+00:00Added an answer on May 18, 2026 at 4:07 am

    If you are using Linq.DataContext then it does indeed keep track of changes for you.

    The function to reference is System.Data.Linq.DataContext.GetChangeSet. Although GetChangeSet can be called at any time it would be good to reference the Remarks section in the MSDN documentation.

    You can check / take action on submit…

    Here is a quick example of how you can override SubmitChanges on a DataContext and take actions at that point.

    The example shows that you can modify the data before final submit, you can also keep track and take special action when specific members are updated:

    namespace ExampleProject1.Models
    {
        public partial class ExampleProject1DataContext
        {
            public override void SubmitChanges(ConflictMode failureMode)
            {
                ManangeAndProcessChangeSet(base.GetChangeSet());
                base.SubmitChanges(failureMode);
            }
    
            private void ManangeAndProcessChangeSet(ChangeSet changeSet)
            {
                DateTime now = DateTime.UtcNow;
    
                if (changeSet.Inserts.Count > 0)
                {
                    ProcessInserts(changeSet.Inserts, now);
                }
    
                if (changeSet.Updates.Count > 0)
                {
                    ProcessUpdates(changeSet.Updates, now);
                }
    
                if (changeSet.Deletes.Count > 0)
                {
                    ProcessDeletes(changeSet.Deletes, now);
                }
            }
    
            private void ProcessInserts(IList<object> list, DateTime now)
            {
                IEnumerable<Cake> cakes = list.OfType<Cake>();
                IEnumerable<Topping> toppings = list.OfType<Topping>();
    
                // Update the created and modified times.
                foreach (Cake cake in cakes)
                {
                    cake.Guid = Guid.NewGuid();
                    cake.CreatedDateTime = now;
                    cake.ModifiedDateTime = now;
                }
                foreach (Topping topping in toppings)
                {
                    topping.Guid = Guid.NewGuid();
                    topping.CreatedDateTime = now;
                    topping.ModifiedDateTime = now;
                }
            }
    
            private void ProcessUpdates(IList<object> list, DateTime now)
            {
                IEnumerable<Cake> cakes = list.OfType<Cake>();
                IEnumerable<Topping> toppings = list.OfType<Topping>();
    
                // Update the created and modified times.
                foreach (Cake cake in cakes)
                {
                    ProcessUpdates(cake, now);
                }
                foreach (Topping topping in toppings)
                {
                    topping.ModifiedDateTime = now;
                }
            }
    
            private void ProcessDeletes(IList<object> list, DateTime now)
            {
                IEnumerable<Cake> cakes = list.OfType<Cake>();
                IEnumerable<Topping> toppings = list.OfType<Topping>();
    
                // Could create tasks here to delete associated stored files for cakes and toppings.
            }
    
            private bool ProcessUpdates(Cake cake, DateTime now)
            {
                bool modified = false;
    
                ModifiedMemberInfo[] mmi = context.Cakes.GetModifiedMembers(cake);
                foreach (ModifiedMemberInfo mi in mmi)
                {
                    switch (mi.Member.Name)
                    {
                        case "CountOfItemsSold":
                            // Exclude from updating the modified date.
                            break;
    
                        case "IsExpired":
                            if ((bool)mi.CurrentValue)
                            {
                                cake.ExpiredDateTime = now;
                            }
                            else
                            {
                                cake.ExpiredDateTime = null;
                            }
                            modified = true;
                            break;
    
                        default:
                            modified = true;
                            break;
                    }
                }
    
                if (modified)
                {
                    cake.ModifiedDateTime = now;
                }
    
                return modified;
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After following instructions from orbeons wiki From: http://wiki.orbeon.com/forms/doc/user-guide/form-builder-user-guide#TOC-Creating-a-PDF-template-for-use-wit Non-exclusive checkboxes Use PDF checkboxes Use
I'm at my wit's end. The Share Point guy got a brain tumor and
I have been assigned wit the task to write a program that takes a
I'm at my wit's end with this. Can anyone see anything wrong with this
I am at wit's end. I have a working install of python 2.6.5 with
I have a problem wit the software I'm working on. We are accessing Windows
Lets say I have a selectbox wit 10 predefined amounts and an option other.
I have a big div wit a lot of smaller divs within it. Say,
For now jQuery timepicker component is invoked wit click on input. This is timepicker
Ok so im at my wit's end here. I have tried every imaginable thing

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.