Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadResult{TEntity}" /> class.
        /// </summary>
        /// <param name="loadOperation">The load operation which have been completed.</param>
        /// <exception cref="System.ArgumentException">load operation must have been completed successfully</exception>
        public LoadResult(LoadOperation <TEntity> loadOperation)
        {
            if (loadOperation.IsCanceled || loadOperation.HasError || !loadOperation.IsComplete)
            {
                throw new ArgumentException(Resources.OperationNotComplete);
            }

            // LoadOperation.Entities is a ReadOnlyObservableCollection which inherit ReadOnlyCollection
            _loadedEntites = (ReadOnlyCollection <TEntity>)loadOperation.Entities;

            EntityQuery = loadOperation.EntityQuery;
            AllEntities = loadOperation.AllEntities;

            TotalEntityCount = loadOperation.TotalEntityCount;
            LoadBehavior     = loadOperation.LoadBehavior;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 等待数据载入,提供一个同步方法的扩展
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="q"></param>
        /// <returns></returns>
        public static IEnumerable <TEntity> waitLoaded <TEntity>(this LoadOperation <TEntity> q) where TEntity : Entity
        {
            System.Threading.AutoResetEvent auto = new System.Threading.AutoResetEvent(false);
            q.Completed += (a, b) =>
            {
                auto.Set();
            };

            auto.WaitOne();

            auto.Dispose();
            if (null != q.Error)
            {
                throw q.Error;
            }
            return(q.Entities);
        }