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

add CreateEntities<T>(List<T> entities) method

1 Answer 52 Views
Web Services
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 08 Mar 2010, 02:31 AM
   public string CreateEntity<T>(T entity) 
        { 
            try 
            { 
                this.scope.Add(entity); 
                IObjectId entityId = Database.GetObjectId(entity); 
                return entityId.ToString(); 
            } 
            catch (Telerik.OpenAccess.OpenAccessException ex) 
            { 
                this.RollBackTransaction(this.scope); 
                throw ex; 
            } 
        } 
 
            /// <summary> 
        ///  Create entities. 
        /// </summary> 
        /// <typeparam name="T"></typeparam> 
        /// <param name="entities"></param> 
        /// <returns></returns
        public int CreateEntities<T>(List<T> entities) 
        { 
            foreach (T t in entities) 
            { 
                CreateEntity(t); 
            } 
            scope.Transaction.Commit(); 
            return entities.Count(); 
 
        } 
in DataManager.cs  add  public int CreateEntities<T>(List<T> entities) .

I wondee if that method is more faster in the create method.


1 Answer, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 10 Mar 2010, 07:04 PM
Hello xu,

The following approach is slightly better:

/// <summary>
///  Create entities.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities"></param>
/// <returns></returns>
public int CreateEntities<T>(List<T> entities)
{
    try
    {
        foreach (T t in entities)
        {
            this.scope.Add(entity);
            IObjectId entityId = Database.GetObjectId(entity);
            return entityId.ToString();
        }
        scope.Transaction.Commit();
        return entities.Count();
    }
    catch (Telerik.OpenAccess.OpenAccessException ex)
    {
        this.RollBackTransaction(this.scope);
        throw ex;
    }
}

Hope that helps.

Sincerely yours,
Damyan Bogoev
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
Web Services
Asked by
xu
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or