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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:24:00+00:00 2026-05-25T17:24:00+00:00

First off, thanks for any help. I am using ria services to insert/update/delete entities

  • 0

First off, thanks for any help. I am using ria services to insert/update/delete entities and save a history of those operations. I want to perform the operation and save the history in ONE call to the service. Right now I am stuck on the insert because I need the new entities ID that is generated on the insert. I might be taking the wrong approach all together (but I hope not). I have overriden the submit method, and am trying to save a snapshot in the history table, I don’t want to save a snapshot of the original version:

    public override bool Submit( ChangeSet changeSet )
    {
        //SUBMIT FIRST SO THE OBJECT(S) HAVE AN ID
        var success = base.Submit( changeSet );
        if ( success )
            foreach ( var changeSetEntry in changeSet.ChangeSetEntries )
            {
                if ( changeSetEntry.Entity is MyBusinessEntity )
                {
                    var newBusinessEntity = (MyBusinessEntity) changeSetEntry.Entity;
                    RecordModifiedMyBusinessEntity( changeSetEntry.Operation, newBusinessEntity );
                }
            }
        return success;
    }

    private void RecordModifiedMyBusinessEntity( DomainOperation operation, MyBusinessEntity newBusinessEntity )
    {
        var hist = new BusinessEntityHistory
        {
            ChangedBy = new AuthenticationService().GetUser().FriendlyName,
            ChangedDate = DateTime.Now,
            Operation = operation.ToString(),
            BusinessEntityId = newBusinessEntity.Id,
            Group = newBusinessEntity.Group,
            Priority = newBusinessEntity.Priority,
            ....
        };
        InsertBusinessEntityHistory( hist );
        //HERE IS WHERE I WANT TO CALL SUBMIT CHANGES AGAIN, BUT 1 - IT'S NOT IN THE CHANGESET,
        //AND 2 - THE OBJECT I ALREADY INSERTED IS IN THE CHANGESET (SO IF I SUBMIT AGAIN, IT GETS 
        //INSERTED TWICE AND NO HISTORY IS SAVED.  AND 3 - I CAN'T DO THE HISTORY BEFORE BECAUSE I DON'T 
        //HAVE THE ID, AND I DON'T WANT TO DO A MAX ID + 1 BECAUSE SOMEONE ELSE MIGHT BE 
        //INSERTING INTO THE SAME TABLE
    }
  • 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-25T17:24:00+00:00Added an answer on May 25, 2026 at 5:24 pm

    Here is the solution I ended up going with:

        public override bool Submit( ChangeSet changeSet )
        {
            //submit the changes
            var success = base.Submit( changeSet );
            if ( success )
            {
                //make a new list of change set entries 
                var entries = new List<ChangeSetEntry>();
                //each change set entry needs an id (not to be confused with the entity's id)
                var maxId = 0;
                //iterate through each change and add historical snapshot.
                foreach ( var changeSetEntry in changeSet.ChangeSetEntries )
                {
                    var entity = changeSetEntry.Entity;
                    var operation = changeSetEntry.Operation;
                    var myEntity = entity as MyEntityType;
                    if ( myEntity != null )
                    {
                        entries.Add( GetHistoryChangeSetEntry( ref maxId, operation, myEntity ) );
                        continue;
                    }
                }
                //make new change set with historical snapshots
                var newChangeSet = new ChangeSet( entries );
                //submit the new change set
                base.Submit( newChangeSet );
            }
            return success;
        }
    
        private ChangeSetEntry GetHistoryChangeSetEntry( ref int maxId, DomainOperation operation, MyEntityType myEntity )
        {
            return new ChangeSetEntry
                    {
                        Id = ++maxId,
                        //We are inserting this change set entry
                        Operation = DomainOperation.Insert,
                        Entity = new MyEntityTypesHistory
                                    {
                                        ChangedBy = ServiceContext.User.Identity.Name,
                                        ChangedDate = DateTime.Now,
                                        //The operation performed on the original entity
                                        Operation = operation.ToString(),
                                        MyEntityId = myEntity.EntityId,
                                        MyEntityField1 = myEntity.EntityField1,
                                        MyEntityField2 = myEntity.EntityField2
                                    }
                    };
        }
    

    I had to make a new change set, and new change set entries for it, and submit changes with the new change set.

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

Sidebar

Related Questions

First off, I am using Windows XP. I have multiple hard drives and it
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
First off, I'm using version 3.7.1 with a jQuery UI framework theme. I'm trying
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First off, there's a bit of background to this issue available on my blog:
First off, I'm working on an app that's written such that some of your
First off, let me start off that I am not a .net developer. The
First off, this question is ripped out from this question. I did it because
First off, I know next to nothing about language theory, and I barely know

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.