New Posts New Posts RSS Feed: Fixup ID for tables that are not connected
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Fixup ID for tables that are not connected

 Post Reply Post Reply
Author
erika View Drop Down
Newbie
Newbie


Joined: 04-Jul-2012
Posts: 5
Post Options Post Options   Quote erika Quote  Post ReplyReply Direct Link To This Post Topic: Fixup ID for tables that are not connected
    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 !
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down