This is a migrated thread and some comments may be shown as answers.

Some questions

28 Answers 187 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
yjh
Top achievements
Rank 1
yjh asked on 28 Aug 2011, 04:59 AM
1. Does the new Context Model can working with TransactionScope?

     If can,

     1.1 More than two DBContext(same or not same database, such as MS Sql Server, Oracle,Sqlite, etc) can using in a TransactionScope ?

     1.2 Is there a example for using Sqlite with TransactionScope ?

2. In ASP.net enviroment, the best practice is to keep DBContext as static or get a new instance on each web quest  or per session ?

3. Multi back end in a rlinq will come or not ?

28 Answers, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 28 Aug 2011, 09:15 AM
Hi yjh,

As for number 2, it is best practice to use the "one-thread-one-context" approach. That is, creating a new Context for each request that comes in. In the knowledge base there is some examples of how to do this. In general there are two approaches of doing this... either have a common master page for all your other pages exposing the created Context or using a ContextFactory.
Both methods are equal, in that they create a Context and store it for retrieval during the lifetime of the request, for example in the HttpContext.Items object under a predefined key

As for your other questions OpenAccess has support for the System.Transactions so you can have multiple datasources enlisting in the same transaction...
0
yjh
Top achievements
Rank 1
answered on 29 Aug 2011, 04:34 AM
Thanks, Henrik ,you are welcome.

Is that to say TransactionScope is not supported ?
0
IT-Als
Top achievements
Rank 1
answered on 30 Aug 2011, 06:31 AM
Hi yjh,

No, in the System.Transactions namespace you have the TransactionScope class... Here's a link to the docs (of OA Classic) on how to use TransactionScope as TransactionProvider instead of the default OpenAccess provider.

TransactionScope provider

Regards

Henrik
0
Nikola
Telerik team
answered on 31 Aug 2011, 04:46 PM
Hi yjh,

Unfortunately as Henrik suggested it is not possible to use TransactionProvider with our new API. Underneath each context is a transaction that is managed by the contexts' public api. If you need to envelop several contexts into one logical transaction you will have to come up with your own solution. Please don't hesitate to contact us if you require more information.

Could you give us a bit more insight on what you are trying to achieve and why you need to have two database operations enlisted in the same transaction. Is that the only solution to your issue? 

As for you last question - yes, multiple backend support is on our roadmap with high priority but I am not able to provide an exact date.

All the best,
Nikola
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 05 Sep 2011, 10:48 AM
It is often in enterprise application that have across database transactions.

It's regret that OpenAccess's new api(Domain model) does't support across database transactions directly now.
0
Jan Blessenohl
Telerik team
answered on 05 Sep 2011, 02:20 PM
Hello Yjh,
Sorry for the confusion. You can use TransactionScope around several context instances. OpenAccess looks for a running system transaction if you do the first write operation in the context. Based on that the OpenAccess or the system.transaction is used.

Regards,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
IT-Als
Top achievements
Rank 1
answered on 05 Sep 2011, 02:33 PM
Hi Jan,

Thanks for elaborating.

Just to get things clear:

The methods of starting and committing a "System.Transactions" transaction is still as pointed out in the classic approach linked to in an earlier reply?

Or does the selecting of "transaction provider" happen behind the scenes of the scope, based on what transaction provider transaction is started first...  if it is OpenAccess->OpenAccess is used.... if a "System.Transactions" transaction is running->TransactionScope is used`?

Regards

Henrik
0
Jan Blessenohl
Telerik team
answered on 05 Sep 2011, 03:12 PM
Hello Henrik,
You can have the context or the txn generation outside, important is the first change that you trigger. This code works fine and nothing is stored if you do not call SaveChanges or Complete.

using (EntitiesModel ctx = new EntitiesModel())
{
    using (var txn = new TransactionScope())
    {
        ctx.Add(new Person());
        ctx.SaveChanges();
        txn.Complete();
    }
    int i = ctx.GetAll<Person>().Count();
}


Greetings,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
IT-Als
Top achievements
Rank 1
answered on 05 Sep 2011, 03:22 PM
Hi Jan,

Thanks for elaborating.
It works like in the classic approach then - as far as I can tell.
Only you have to watch out for doing updates before you actually instantiate the TransactionScope... If you want updates to participate in the TransactionScope transaction you have to put them in between the using statement scope (as per your example).

/Henrik
0
Jan Blessenohl
Telerik team
answered on 05 Sep 2011, 04:16 PM
Hi Henrik,
Yes, that is what you are usually doing.

Best wishes,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 05 Sep 2011, 04:25 PM
I test in sqlite, txn.Complete() is no affection.

Only context.SaveChanges() can determine whether data updated will be persisted.
0
Jan Blessenohl
Telerik team
answered on 05 Sep 2011, 05:07 PM
Hello Yjh,
Do you say that you are using my code and it does not matter if you call txn.complete, the changes are in the database?

All the best,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 06 Sep 2011, 01:22 AM
Yes, if ctx.SaveChanges() is called, updated data saved, otherwise, no changes persisted.

That's why I ask if OA support TransactionScope.
0
Jan Blessenohl
Telerik team
answered on 06 Sep 2011, 08:21 AM
Hi Yjh,
Let me rephrase,
The next two snippets should not store anything:
using (EntitiesModel ctx = new EntitiesModel())
{
    using (var txn = new TransactionScope())
    {
        ctx.Add(new Person());
        ctx.SaveChanges();
        //txn.Complete();
    }
    int i = ctx.GetAll<Person>().Count();
}
using (EntitiesModel ctx = new EntitiesModel())
{
    using (var txn = new TransactionScope())
    {
        ctx.Add(new Person());
        //ctx.SaveChanges();
        txn.Complete();
    }
    int i = ctx.GetAll<Person>().Count();
}

Only if you call both, something will be stored:
using (EntitiesModel ctx = new EntitiesModel())
{
    using (var txn = new TransactionScope())
    {
        ctx.Add(new Person());
        ctx.SaveChanges();
        txn.Complete();
    }
    int i = ctx.GetAll<Person>().Count();
}

Both calls are necessary because the context changes are pushed down to the server during the SaveChanges() call, but the TransactionScope keeps the SQLite transaction running until the closing bracket. You can even call several times SaveChanges() on the scope before closing the transaction bracket.

Greetings,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 06 Sep 2011, 11:04 AM
Please see support ticket(ID: 461121)

There is even no txn.Complete(), but you can see the ParentID of node(ID is 'bb399da7-5a54-48c1-b18e-04d6471d3e9a') change from '8a205e13-476d-4cb0-8be7-2ccfcc7718f4' to 'a092fa8a-07b0-499a-ba90-5e416b75d005'.
0
Jan Blessenohl
Telerik team
answered on 07 Sep 2011, 09:31 AM
Hi Yjh,
In your code you are using Flush(). Flush does not work together with TransactionScope. Please remove the Flush call and it will work.

Kind regards,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 07 Sep 2011, 01:55 PM
Yes, if remove ctx.Flush(), TransactionScope works.

But as described in Support Ticket  459049, without ctx.Flush(), I can't get soft commit.

It seem that when linq in OA query data from database, some time not using 1st cache, without soft commit, the data retrieved will not keep consist with domain model, that may has fatal error.

Similar needs:
http://www.telerik.com/community/forums/orm/development/transaction-handling.aspx
http://www.telerik.com/community/forums/orm/development/transaction-management.aspx
0
Accepted
Jan Blessenohl
Telerik team
answered on 07 Sep 2011, 03:26 PM
Hi Yjh,
I am sorry, but at the moment you have to choose between using flush without transaction scope or not using flush but with transaction scope.

Greetings,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 08 Sep 2011, 01:56 AM
It's a real bad news. Will you plan to provide soft commit and when ?
0
Jan Blessenohl
Telerik team
answered on 08 Sep 2011, 04:18 PM
Hello Yjh,
I have added it to the list. I will try to get it done for the next major release.

Kind regards,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
yjh
Top achievements
Rank 1
answered on 28 Sep 2011, 09:50 AM
The next major release means 2011 q2 sp1 or 2011 q3 ?
0
Jan Blessenohl
Telerik team
answered on 30 Sep 2011, 09:18 AM
Hello Yjh,
Major means Q3.

Greetings,
Jan Blessenohl
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
Jan Blessenohl
Telerik team
answered on 17 Nov 2011, 12:19 PM
Hi Yjh,

The Flush will work now together with System.Transactions. Please try the Q3 2011 version.

Kind regards,
Jan Blessenohl
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

0
yjh
Top achievements
Rank 1
answered on 22 Nov 2011, 03:05 AM
Ok, I can get Flush work properly with TransactionScope.

But if doesn't call context.SaveChanges and just call ts.Complete, OA will throw a TransactionAbortException.
0
Jan Blessenohl
Telerik team
answered on 22 Nov 2011, 10:23 AM
Hi Yjh,
Why should Flush() call SaveChanges? You still can decide to roll back and there can also be additonal changes between the Flush and SaveChanges() call. Flush just means we send everything to the server using the enlisted transaction, you still have to call SaveChanges() to not let us rollback everything.

Greetings,
Jan Blessenohl
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

0
yjh
Top achievements
Rank 1
answered on 23 Nov 2011, 03:26 AM
I nerver say using Flush() call SaveChanges() !

In fact, I mean if not calling context.SaveChanges()  in a TransactionScope(ts),just calling ts.Complete can cause the exception.

Using(var ts = new TransactionScope(...
Using(var context = new FrameworkContext(...
{
    //do some operation

    //context.SaveChanges(); //If comment this line, a exception thrown
    ts.Complete();
}
0
Jan Blessenohl
Telerik team
answered on 23 Nov 2011, 10:09 AM
Hi Yjh,
Because we use late enlistment, it is necessary to call both. We already had this discussion, can you please look through the ticket again?


Jan Blessenohl
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
yjh
Top achievements
Rank 1
answered on 25 Nov 2011, 02:39 PM
Hi Jan, I'm not deep in OA. Anyway, it seem that if using TransactionScope with OA, just keep calling SaveChanges.

Thank you and your team.
Tags
General Discussions
Asked by
yjh
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
yjh
Top achievements
Rank 1
Nikola
Telerik team
Jan Blessenohl
Telerik team
Share this question
or