Data Services Wizard Transaction.Commit()

Thread is closed for posting
6 posts, 0 answers
  1. xu
    xu avatar
    11 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2010 Link to this post

    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.
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 10 Mar 2010 Link to this post

    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.
  3. xu
    xu avatar
    11 posts
    Member since:
    Oct 2008

    Posted 11 Mar 2010 Link to this post

    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.
  4. Peter Bahaa
    Admin
    Peter Bahaa avatar
    26 posts

    Posted 11 Mar 2010 Link to this post

    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.
  5. xu
    xu avatar
    11 posts
    Member since:
    Oct 2008

    Posted 11 Mar 2010 Link to this post

    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!

  6. Peter Bahaa
    Admin
    Peter Bahaa avatar
    26 posts

    Posted 12 Mar 2010 Link to this post

    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.
Back to Top