Get info about valid commites

8 posts, 0 answers
  1. darko blazinic
    darko blazinic avatar
    4 posts
    Member since:
    Oct 2002

    Posted 16 Nov 2015 Link to this post

    Is it possible to find how much the objects could be validly committed before the error occurred?
  2. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 19 Nov 2015 Link to this post

    Hi Darko,

    Thank you for contacting us.

    I kindly ask you to provide us with the following details:

    1. Which backend do you consume (SQL Server, or Oracle, or PostgreSQL, or else)?
    2. What is the scenario on your side (you are interested in the backends' thresholds, you are implementing validation of the data, you are implementing error handling when the operations fail)?

    Thank you in advance for your cooperation.

    Regards,
    Doroteya
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
  4. darko blazinic
    darko blazinic avatar
    4 posts
    Member since:
    Oct 2002

    Posted 19 Nov 2015 in reply to Doroteya Link to this post

    Hi,

    1. beckend is Oracle

    2. My scenario : if 80% of inserts (updates or deletes) is OK commit all trans other roll back. Is this possible? 

  5. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 23 Nov 2015 Link to this post

    Hello Darko,
    Thank you for providing the additional information.
    In general, the OpenAccessContext instance is working with transactions. So when you call SaveChanges, then all the necessary operations are fired against the server and a commit is called in the end. This means that either all or no data is commited to the database. In case you want to find out, which operations would happen before the commit, you can use our tracking api to figure this out. You might find this link interesting.

    http://docs.telerik.com/data-access/developers-guide/crud-operations/developer-guide-crud-saving

    I hope this information is helpful for you.
    Do come back in case you have any other question.

    Regards,
    Ralph Waldenmaier
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.

     
  6. darko blazinic
    darko blazinic avatar
    4 posts
    Member since:
    Oct 2002

    Posted 23 Nov 2015 in reply to Ralph Waldenmaier Link to this post

    In other words it isn't possible to work with transactions, because it is wrap out to SaveChanges method. So I can't use benefit of ORM in conjunction with custom handling of transaction.
     
  7. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 24 Nov 2015 Link to this post

    Hello Darko,
    Of course you can handle the transactions in a manual fashion. Please see this link for more details.

    http://docs.telerik.com/data-access/feature-reference/api/context-api/feature-ref-api-context-api-handling-transactions

    This allows you to handle transactions in a convenient way.
    There is also another possibility to handle transactions by using the classic approach. For this you might find this link interesting.

    http://www.telerik.com/help/openaccess-classic/using-transactions-in-openaccess.html

    Hence, to use the classic approach you need to expose the scope via your context. Please see the following snippet of how to do this.

    public partial class MySampleContext : OpenAccessContext
    {
        public IObjectScope GetMyScope()
        {
            return base.GetScope();
        }
    }

    Here I created a partial class of the context and am providing the IObjectScope instance which can be obtained from the OpenAccessContext base class.

    I hope this gives you the flexibility you need to handle transactions in your project.
    Feel free to ask in case you need further assistance.


    Regards,
    Ralph Waldenmaier
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.

     
  8. darko blazinic
    darko blazinic avatar
    4 posts
    Member since:
    Oct 2002

    Posted 30 Nov 2015 in reply to Ralph Waldenmaier Link to this post

    Hello Ralph,

    I was try to expose scope as you write, but i keep geting error "The method Begin is not supported for managed transactions."

     public partial class DarkoWebApiDomainContext : OpenAccessContext, IDarkoWebApiDomainContextUnitOfWork     {         public IObjectScope GetDarkoWebApiDomainScope()         {             return base.GetScope();         }

    ...

    and in method call

                DarkoWebApiDomainContext dbContext = new DarkoWebApiDomainContext();              IObjectScope scope = dbContext.GetDarkoWebApiDomainScope();

     scope.Transaction.Begin(); --> error

    What I doing wrong?

  9. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 03 Dec 2015 Link to this post

    Hi Darko,
    You are right, the previously provided GetMyScope can not work with custom transactions since it was bound to the existing context. In order to work with custom transactions, the GetMyScope method must look like this.

    public IObjectScope GetMyScope()
    {                                   
        return base.GetScope().Database.GetObjectScope();
    }

    Here you will get a completely isolated object scope which has nothing to do with the context you used to create the object scope.

    Revisiting your initial question. You said you want to commit if 80% of your inserts or deletes were successful. You can try to achieve this by flushing chunks of your data to the database and if you have no failure up to a certain point (80%), you can commit that data to the database.
    In case of a failure, in order to get the information about the object that failed, you can either enhance the log level to see more details, or examine the exception which will tell you about the failed object.

    Do not hesitate to contact us again in case you have any other issue.

    Regards,
    Ralph Waldenmaier
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top
DevCraft banner