예제 #1
0
        /// <summary>
        /// 返回特定类型的对象的集合,其中类型由 T 参数定义
        /// </summary>
        public IDbQueryable <T> GetTable <T>()
        {
            DbQueryable <T> query = new DbQueryable <T>(this, new List <DbExpression> {
                new DbExpression(DbExpressionType.GetTable, Expression.Constant(typeof(T)))
            });

            return(query);
        }
예제 #2
0
        /// <summary>
        /// 返回特定类型的对象的集合,其中类型由 T 参数定义
        /// <para>
        /// 适用场景:
        /// 多个导航属性类型一致,用此重载可解决 a.Navigation.Property 的表别名定位问题
        /// </para>
        /// </summary>
        /// <typeparam name="T">元素类型</typeparam>
        /// <typeparam name="TProperty">导航属性类型</typeparam>
        /// <param name="path">导航属性,注意在一组上下文中第一个 GetTable 的这个参数将被自动忽略</param>
        /// <returns></returns>
        public IDbQueryable <TProperty> GetTable <T, TProperty>(Expression <Func <T, TProperty> > path)
        {
            DbQueryable <TProperty> query = new DbQueryable <TProperty>(this, new List <DbExpression>
            {
                new DbExpression(DbExpressionType.GetTable, new[] { Expression.Constant(typeof(TProperty)), (Expression)path }),
            });

            return(query);
        }
예제 #3
0
        /// <summary>
        /// 创建查询
        /// </summary>
        public IDbQueryable <TResult> CreateQuery <TResult>(DbExpression dbExpression = null)
        {
            List <DbExpression> collection = new List <DbExpression>(this.DbExpressions.Count + (dbExpression != null ? 1 : 0));

            collection.AddRange(this.DbExpressions);
            if (dbExpression != null)
            {
                collection.Add(dbExpression);
            }

            IDbQueryable <TResult> query = new DbQueryable <TResult>(this.DbContext, collection);

            return(query);
        }