7 Answers, 1 is accepted
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
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?
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
Of course you can handle the transactions in a manual fashion. Please see this link for more details. 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
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?
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