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

  • Home
  • SEARCH
  • 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 564667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:47:28+00:00 2026-05-13T12:47:28+00:00

We have a Silverlight application that uses WCF Data Services. We want to add

  • 0

We have a Silverlight application that uses WCF Data Services. We want to add logging functionality: when a new row is generated, the primary key for this new row is also recorded in the logging table. The row generation and the logging should occur within the same transaction. The primary keys are generated via the database (using the IDENTITY keyword).

This might best be illustrated with an example. Here, I create a new Customer row, and in the same transaction I write the Customer’s primary key to an AuditLog row. This example uses a thick client and the Entity Framework:

    using (var ts = new TransactionScope())
    {
        AuditTestEntities entities = new AuditTestEntities();
        Customer c = new Customer();
        c.CustomerName = "Acme Pty Ltd";
        entities.AddToCustomer(c);
        Debug.Assert(c.CustomerID == 0);
        entities.SaveChanges();
        // The EntityFramework automatically updated the customer object
        // with the newly generated key
        Debug.Assert(c.CustomerID != 0);
        AuditLog al = new AuditLog();
        al.EntryDateTime = DateTime.Now;
        al.Description = string.Format("Created customer with customer id {0}", c.CustomerID);
        entities.AddToAuditLog(al);
        entities.SaveChanges();
        ts.Complete();
    }

It’s a trivial problem when developing a thick client using Entity Framework.

However, using Silverlight and ADO.NET data services:

  • SaveChanges can only be invoked
    asynchronously
  • I’m not sure TransactionScope is available
  • I’m not sure if generated keys can be reflected in the client Edit: According to Alex James they are indeed reflected in the client

So, will this even be possible?

  • 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-13T12:47:28+00:00Added an answer on May 13, 2026 at 12:47 pm

    Short Answer: No this is not even possible

    Okay… so:

    1. Generated Keys are reflected in the client.
    2. You can transact one SaveChanges operation by using DataServiceContext.SaveChanges(SaveChangesOption.Batch)

    But unfortunately you can’t do anything to tie one request to the response of another, and wrap them both in one transaction.

    However…

    If you change the model by making a CustomerAuditLog method that derives from AuditLog:

    // Create and insert customer ...
    // Create audit log and relate to un-insert customer
    CustomerAuditLog al = new CustomerAuditLog(); 
    al.EntryDateTime = DateTime.Now; 
    al.Description = string.Format("Created customer with {Customer.ID}");
    // assuming your entities implement INotifyPropertyChanging and you are using
    // the Data Services Update to .NET 3.5 SP1 to use DataServiceCollection 
    // to notify the DataServiceContext that a relationship has been formed. 
    //
    // If not you will manually need to tell Astoria about the relationship too.
    al.Customer = c; 
    entities.AddToAuditLog(al); 
    entities.SaveChanges();
    

    And having some sort of logic deep in your underlying DataSource or maybe even the database to replace {Customer.ID} with the appropriate value.

    You might be able to get it to work, because if two inserts happen in the same transaction and one (CustomerAuditLog) depends on another (Customer) they should be ordered appropriately by the underlying data source.

    But as you can see this approach is kind of hacky, you don’t want a Type for each possible audit message do you! And … it might not even work.

    Hope this helps

    Alex

    Data Services Team, Microsoft

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

Sidebar

Related Questions

I have a Silverlight / WCF RIA Services application that uses EF 4. Currently,
We have a silverlight project that uses RIA services. There is some code that
I am building a silverlight application that needs to have a login page and
I have a web application that launches as second web application in a new
I have a Silverlight application that is using a navigation frame. I am trying
I have silverlight application. What I want is. If my user clicks on Button
I have a DataGrid in my Silverlight application that I would like to highlight
I have read that silverlight application will be downloaded as a XAP file on
I'm trying to do a school project where we are to create a Silverlight
I'm attempting to iterate through all User Profiles in SharePoint 2010 from a Silverlight

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.