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

Data Services Wizard Transaction.Commit()

5 Answers 94 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.
xu
Top achievements
Rank 1
xu asked on 06 Mar 2010, 02:19 AM
Hi,
I built a WCF Project with the Data Services Wizard. I  recognized that theDataManager Class 'InitializeManager()' method has already used "this.scope.TransactionProperties.AutomaticBegin = true;" ,I don't know whether or not I should use the "scope.Transaction.Commit();"
WCFServiceClient wcfcl = new WCFServiceClient(); 
Person p = new Person(); 
p.Name="Test"
wcfcl .CreatePerson(p); 
 
Because of the "wcfcl.CreatPerson(p);"  never saved the data actually.
Thanks.

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 10 Mar 2010, 03:57 PM
Hi xu,

This problem has already been addressed and will be fixed in the next version of the Data Services wizard. In the meantime, please add manually the scope.Transaction.Commit() line at the end of the try{} block of the according method in the DataManager. We are sorry for the inconvenience.

Sincerely yours,
Alexander
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
xu
Top achievements
Rank 1
answered on 11 Mar 2010, 06:04 AM
Hi,Alexander
Thanks  for your reply.I had added manually the scope.Transaction.Commit() line at the end of the try{} block of the according method in the DataManager.But it is not a proper idea. It will absorb much of transaction time when I add a great quantity entities.
0
Peter Bahaa
Telerik team
answered on 11 Mar 2010, 08:05 PM
Hello xu,

To execute multiple insert operations in one step you need to create a new function that accepts a list of your new entities then add those entities to your scope provider. The final step is to commit the transaction,

Ffirst add the following function to your data manager

01.public List<string> CreateEntities<T>(List<T> entitiesList)
02.        {
03.            try
04.            {
05.                List<string> entitiesIds = new List<string>();
06.                foreach (var entity in entitiesList)
07.                {
08.                    this.scope.Add(entity);
09.  
10.                    IObjectId entityId = Database.GetObjectId(entity);
11.                    entitiesIds.Add(entityId.ToString());
12.                }
13.  
14.                this.scope.Transaction.Commit();
15.  
16.                return entitiesIds;
17.            }
18.            catch (Telerik.OpenAccess.OpenAccessException ex)
19.            {
20.                this.RollBackTransaction(this.scope);
21.                throw ex;
22.            }
23.        }

You should do the following for each entity that you want to execute large sum of insert operations:
Aadd the following line to the service interface

1.[OperationContract]
2.List<string> CreateCustomers(List<ClassLibrary1.Customer> customers);

You should just change Customer with your entity name:
Then you need to add this function implementation in the service code behind,
1.public List<string> CreateCustomers(List<ClassLibrary1.Customer> customers)
2.{
3.    return dataManager.CreateEntities<ClassLibrary1.Customer>(customers);
4.}


Best wishes,
Peter Bahaa
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
xu
Top achievements
Rank 1
answered on 12 Mar 2010, 01:12 AM
Hi,
    Thanks,but why cant Auto-generate the Source File from the DSW?
     It will be better if the DSW generate complete standard functions to support CURD  operation for entities!

0
Peter Bahaa
Telerik team
answered on 12 Mar 2010, 05:19 PM
Hi xu,

We will add this enhancement to our next release which is scheduled for this month.

All the best,
Peter Bahaa
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
xu
Top achievements
Rank 1
Answers by
Alexander
Telerik team
xu
Top achievements
Rank 1
Peter Bahaa
Telerik team
Share this question
or