Print Page | Close Window

Fixup ID for tables that are not connected

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3515
Printed Date: 02-Jun-2025 at 11:44am


Topic: Fixup ID for tables that are not connected
Posted By: erika
Subject: Fixup ID for tables that are not connected
Date Posted: 04-Jul-2012 at 3:22am
Hi,

I have several tables; some are connected, some are not. During save, when I save a record in table A, it should create a record in table B. Table B has ID field that should be retrieved from table A's ID. However, there's no association between table A & B. I can't add association because ID field in table A is also used by other tables as foreign key. 

During Save process, the table A's ID saved in table B are not fixed up, because there's no association.

To solve this issue, I tried to use EntityServerSaveInterceptor to intercept the save process. Here's what I'm trying to do in the interceptor.

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                    TransactionSettings.Default = new TransactionSettings(IsolationLevel.ReadCommitted, TimeSpan.FromSeconds(30), true);

base.ExecuteSave();

//get ID value in table A
//update the ID field in table B

scope.Complete();

                    return true;
                }

However, I get error: 
"The transaction specified for TransactionScope has a different IsolationLevel than the value requested for the scope."

I'm not sure whether this is allowed. If not, could anyone suggest a solution ? Thanks a lot !



Replies:
Posted By: DenisK
Date Posted: 05-Jul-2012 at 5:31pm
Hi Erika,

Try the following code instead.

this.SaveOptions.TransactionSettings = new TransactionSettings(IsolationLevel.ReadCommitted, TimeSpan.FromSeconds(30), true);
var trxOptions = this.SaveOptions.TransactionSettings.ToTransactionOptions();

var scope = new TransactionScope(TransactionScopeOption.RequiresNew, trxOptions);
using (scope) 
{
..........Your code here............
}

1. Notice that I use a different TransactionScope(TransactionScopeOption, TransactionOptions) constructor here. There appears to be a bug in .NET when using the TransactionScope(TransactionScopeOption) constructor.

2. If you want to modify the TransactionSettings on the server, use this.SaveOptions.TransactionSettings instead. By the time the save gets to the server, it'll grab the TransactionSettings from SaveOptions and so this is the instance that you want to modify.



Print Page | Close Window