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

2 posts, 1 answers
  1. xu
    xu avatar
    11 posts
    Member since:
    Oct 2008

    Posted 07 Mar 2010 Link to this post

       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.


  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 10 Mar 2010 Link to this post

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