示例#1
0
        /// <summary>
        /// Loads instances of <typeparamref name="TModel"/>.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="query"></param>
        /// <param name="depth"></param>
        /// <param name="provider"></param>
        /// <param name="transactionContext"></param>
        /// <returns></returns>
        public static DataModelCollection <TModel> LoadMany <TModel>(DataModelQuery <TModel> query, int?depth,
                                                                     DataProviderBase provider,
                                                                     DbTransaction transactionContext)
            where TModel : DataModel
        {
            DataModelCollection <TModel> ret = depth.HasValue
                ? provider.DeepLoadModels(query, depth, transactionContext)
                : provider.DeepLoadModels(query, transactionContext);

            return(ret);
        }
示例#2
0
        /// <summary>
        /// Loads an instance of <see cref="DataModel{TEntity}"/>.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="deep"></param>
        /// <param name="provider"></param>
        /// <param name="transactionContext"></param>
        /// <returns></returns>
        public static DataModelCollection <DataModel <TEntity> > LoadMany(DataModelQuery <DataModel <TEntity> > query, bool deep,
                                                                          DataProviderBase provider, DbTransaction transactionContext)
        {
            if (provider == null)
            {
                provider = ProviderDefaults.AppProvider;
            }
            if (deep)
            {
                return(LoadMany(query, null, provider, transactionContext));
            }
            var col = provider.LoadModels(query, transactionContext);
            var ret = new DataModelCollection <DataModel <TEntity> >(col);

            return(ret);
        }
示例#3
0
        /// <summary>
        /// Loads an instance of <see cref="DataModel{TEntity}"/>.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="depth"></param>
        /// <param name="provider"></param>
        /// <param name="transactionContext"></param>
        /// <returns></returns>
        public static DataModelCollection <DataModel <TEntity> > LoadMany(DataModelQuery <DataModel <TEntity> > query, int?depth,
                                                                          DataProviderBase provider, DbTransaction transactionContext)
        {
            DataModelCollection <DataModel <TEntity> > col;

            if (depth.HasValue)
            {
                col = provider.DeepLoadModels(query, depth, transactionContext);
            }
            else
            {
                col = provider.DeepLoadModels(query, transactionContext);
            }
            var ret = new DataModelCollection <DataModel <TEntity> >(col);

            return(ret);
        }
示例#4
0
        /// <summary>
        /// Loads instances of <typeparamref name="TModel"/>.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="query"></param>
        /// <param name="deep"></param>
        /// <param name="provider"></param>
        /// <param name="transactionContext"></param>
        /// <returns></returns>
        public static DataModelCollection <TModel> LoadMany <TModel>(DataModelQuery <TModel> query, bool deep,
                                                                     DataProviderBase provider,
                                                                     DbTransaction transactionContext)
            where TModel : DataModel
        {
            if (provider == null)
            {
                provider = ProviderDefaults.AppProvider;
            }
            if (deep)
            {
                return(LoadMany(query, null, provider, transactionContext));
            }
            DataModelCollection <TModel> ret = provider.LoadModels(query, transactionContext);

            return(ret);
        }
示例#5
0
 /// <summary>
 /// Iterates through the items in the collection
 /// and saves their changes, the context of the
 /// database <paramref name="transactionContext"/>.
 /// If parameter <paramref name="deep"/> is true, the entire
 /// object graph is saved where the properties
 /// of each item is itself a <see cref="DataModel"/>.
 /// </summary>
 /// <param name="deep"></param>
 /// <param name="transactionContext"></param>
 public void Save(bool deep, DbTransaction transactionContext)
 {
     if (DataProvider == null)
     {
         throw new InvalidOperationException("Repository has not been assigned.");
     }
     if (deep)
     {
         DataProvider.DeepSaveModels(this, transactionContext);
     }
     else
     {
         var col = new DataModelCollection <TModel>();
         foreach (var e in this)
         {
             e.SynchronizeFields(SyncTo.FieldMappedData);
             if (e.IsNew || e.IsDirty || e.MarkDeleted)
             {
                 col.Add(e);
             }
         }
         DataProvider.SaveModels(col, transactionContext);
     }
 }