IInstantFeedbackSource <TProjection> IUnitOfWorkFactory <TUnitOfWork> .CreateInstantFeedbackSource <TEntity, TProjection, TPrimaryKey>(
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection)
        {
            var threadSafeProperties = new TypeInfoProxied(TypeDescriptor.GetProperties(typeof(TProjection)), null).UIDescriptors;

            if (projection == null)
            {
                projection = x => x as IQueryable <TProjection>;
            }
            var context = getContext();

            context.MergeOption = MergeOption.NoTracking;
            var source = new WcfInstantFeedbackDataSource
            {
                UseExtendedDataQuery = GetDbRepositoryQuery(getRepositoryFunc, projection).UseExtendedDataQuery,
                DataServiceContext   = context
            };
            var keyProperties = ExpressionHelper.GetKeyProperties(getRepositoryFunc(getUnitOfWork()).GetPrimaryKeyExpression);
            var keyExpression = keyProperties.Select(p => p.Name).Aggregate((l, r) => l + ";" + r);

            source.GetSource += (s, e) =>
            {
                e.Query         = GetDbRepositoryQuery(getRepositoryFunc, projection).Query;
                e.KeyExpression = keyExpression;
                e.Handled       = true;
            };
            return(new InstantFeedbackSource <TProjection>(source, threadSafeProperties));
        }
예제 #2
0
        IInstantFeedbackSource <TProjection> IUnitOfWorkFactory <TUnitOfWork> .CreateInstantFeedbackSource <TEntity, TProjection, TPrimaryKey>(
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection)
        {
            var threadSafeProperties = new TypeInfoProxied(TypeDescriptor.GetProperties(typeof(TProjection)), null).UIDescriptors;

            if (projection == null)
            {
                projection = x => x as IQueryable <TProjection>;
            }
            var source = new EntityInstantFeedbackSource((GetQueryableEventArgs e) => e.QueryableSource = projection(getRepositoryFunc(createUnitOfWork())))
            {
                KeyExpression = getRepositoryFunc(createUnitOfWork()).GetPrimaryKeyPropertyName(),
            };

            return(new InstantFeedbackSource <TProjection>(source, threadSafeProperties));
        }
        IInstantFeedbackSource <TProjection> IUnitOfWorkFactory <TUnitOfWork> .CreateInstantFeedbackSource <TEntity, TProjection, TPrimaryKey>(
            Func <TUnitOfWork, IRepository <TEntity, TPrimaryKey> > getRepositoryFunc,
            Func <IRepositoryQuery <TEntity>, IQueryable <TProjection> > projection)
        {
            var threadSafeProperties = new TypeInfoProxied(TypeDescriptor.GetProperties(typeof(TProjection)), null).UIDescriptors;

            if (projection == null)
            {
                projection = x => x as IQueryable <TProjection>;
            }
            var keyProperties = ExpressionHelper.GetKeyProperties(getRepositoryFunc(createUnitOfWork()).GetPrimaryKeyExpression);
            var keyExpression = keyProperties.Select(p => p.Name).Aggregate((l, r) => l + ";" + r);
            var source        = new EntityInstantFeedbackSource((DevExpress.Data.Linq.GetQueryableEventArgs e) => e.QueryableSource = projection(getRepositoryFunc(createUnitOfWork())))
            {
                KeyExpression = keyExpression
            };

            return(new InstantFeedbackSource <TProjection>(source, threadSafeProperties));
        }