Ejemplo n.º 1
0
        /// <summary>
        /// 从当前数据源中查找指定仓库对应的表。
        /// </summary>
        /// <typeparam name="TRepository">要查找这个仓库对应的表。
        /// 如果这个参数传入 null,则表示查找主表(最左边的表)。</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="alias">
        /// 要查找表的别名。
        /// 如果仓库在本数据源中匹配多个实体源,那么将使用别名来进行精确匹配。
        /// 如果仓库在本数据源中只匹配一个实体源,那么忽略本参数。
        /// </param>
        /// <returns></returns>
        public static ITableSource FindTable <TRepository>(this ISource source, string alias = null)
            where TRepository : EntityRepository
        {
            var repo = RF.Concrete <TRepository>();

            return(source.FindTable(repo, alias));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造一个查询对象。
        /// </summary>
        /// <param name="from">要查询的数据源。</param>
        /// <param name="selection">
        /// 要查询的内容。
        /// 如果本属性为空,表示要查询所有数据源的所有属性。
        /// </param>
        /// <param name="where">查询的过滤条件。</param>
        /// <param name="orderBy">
        /// 查询的排序规则。
        /// 可以指定多个排序条件。
        /// </param>
        /// <param name="isCounting">
        /// 是否只查询数据的条数。
        ///
        /// 如果这个属性为真,那么不再需要使用 Selection。
        /// </param>
        /// <param name="isDistinct">是否需要查询不同的结果。</param>
        /// <returns></returns>
        public IQuery Query(
            ISource from,
            IQueryNode selection    = null,
            IConstraint where       = null,
            List <IOrderBy> orderBy = null,
            bool isCounting         = false,
            bool isDistinct         = false
            )
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            var    tableQuery = new TableQuery();
            IQuery query      = tableQuery;

            query.IsCounting = isCounting;
            query.IsDistinct = isDistinct;
            query.Selection  = selection;
            query.From       = from;
            query.Where      = where;
            tableQuery.SetOrderBy(orderBy);
            if (from.NodeType == QueryNodeType.TableSource)
            {
                tableQuery.MainTable = from as ITableSource;
            }
            else
            {
                tableQuery.MainTable = from.FindTable();
            }
            return(query);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 通过左数据源和右实体数据源,以及从左到右的引用属性,来构造一个连接。
        /// </summary>
        /// <param name="left">左数据源。</param>
        /// <param name="right">右实体数据源。</param>
        /// <param name="leftToRight">从左到右的引用属性。</param>
        /// <returns></returns>
        public IJoin Join(
            ISource left,
            ITableSource right,
            IRefProperty leftToRight
            )
        {
            var leftSource = left.FindTable(leftToRight.OwnerType);

            var condition = this.Constraint(
                leftSource.Column(leftToRight),
                right.Column(Entity.IdProperty)
                );

            var joinType = leftToRight.Nullable ? JoinType.LeftOuter : JoinType.Inner;

            return(Join(left, right, condition, joinType));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 构造一个查询对象。
        /// </summary>
        /// <param name="from">要查询的数据源。</param>
        /// <param name="selection">
        /// 要查询的内容。
        /// 如果本属性为空,表示要查询所有数据源的所有属性。
        /// </param>
        /// <param name="where">查询的过滤条件。</param>
        /// <param name="orderBy">
        /// 查询的排序规则。
        /// 可以指定多个排序条件。
        /// </param>
        /// <param name="isCounting">
        /// 是否只查询数据的条数。
        ///
        /// 如果这个属性为真,那么不再需要使用 Selection。
        /// </param>
        /// <param name="isDistinct">是否需要查询不同的结果。</param>
        /// <param name="top">如果指定此属性,表示需要查询的条数。</param>
        /// <returns></returns>
        public IQuery Query(
            ISource from,
            IQueryNode selection    = null,
            IConstraint where       = null,
            List <IOrderBy> orderBy = null,
            bool isCounting         = false,
            bool isDistinct         = false,
            int?top = null
            )
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            IQuery query = new TableQuery();

            query.IsCounting = isCounting;
            query.IsDistinct = isDistinct;
            query.Top        = top;
            query.Selection  = selection;
            query.From       = from;
            query.Where      = where;
            (query as TableQuery).SetOrderBy(orderBy);
            if (from.NodeType == QueryNodeType.TableSource)
            {
                (query as TableQuery).MainTable = from as ITableSource;
            }
            else
            {
                (query as TableQuery).MainTable = from.FindTable();
            }
            //if (orderBy != null)
            //{
            //    var ob = query.OrderBy;
            //    for (int i = 0, c = orderBy.Count; i < c; i++)
            //    {
            //        var item = orderBy[i];
            //        ob.Add(item);
            //    }
            //}
            return(query);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 从当前数据源中查找指定仓库对应的表。
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="entityType">要查找这个仓库对应的表。
        /// 如果这个参数传入 null,则表示查找主表(最左边的表)。</param>
        /// <param name="alias">
        /// 要查找表的别名。
        /// 如果仓库在本数据源中匹配多个实体源,那么将使用别名来进行精确匹配。
        /// 如果仓库在本数据源中只匹配一个实体源,那么忽略本参数。
        /// </param>
        /// <returns></returns>
        public static ITableSource FindTable(this ISource source, Type entityType, string alias = null)
        {
            var repo = RepositoryFactoryHost.Factory.FindByEntity(entityType);

            return(source.FindTable(repo, alias));
        }