示例#1
0
        /// <summary>
        /// 查询带聚合导航属性的对象集合
        /// </summary>
        /// <typeparam name="TFirst"></typeparam>
        /// <typeparam name="TSecond"></typeparam>
        /// <param name="cnn"></param>
        /// <param name="provider"></param>
        /// <param name="transaction"></param>
        /// <param name="splitOn"></param>
        /// <returns></returns>
        public static IEnumerable <TFirst> Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(this IDbConnection cnn, SqlProvider provider, IDbTransaction transaction = null)
            where TFirst : IBaseEntity
            where TSecond : IBaseEntity
            where TThird : IBaseEntity
            where TFourth : IBaseEntity
            where TFifth : IBaseEntity
            where TSixth : IBaseEntity
            where TSeventh : IBaseEntity
        {
            EntityObject firstEntity = EntityCache.QueryEntity(typeof(TFirst));
            string       splitOn     = GetSplitOn <TFirst>(provider);

            if (!string.IsNullOrEmpty(splitOn))
            {
                //导航属性列表
                var navigationList = provider.JoinList.Where(x => x.Action == JoinAction.Navigation && x.IsMapperField).ToList();
                //把所有实体的信息存下做导航关联索引
                List <TFirst>   firsts   = new List <TFirst>();
                List <TSecond>  seconds  = new List <TSecond>();
                List <TThird>   thirds   = new List <TThird>();
                List <TFourth>  fourths  = new List <TFourth>();
                List <TFifth>   fifths   = new List <TFifth>();
                List <TSixth>   sixths   = new List <TSixth>();
                List <TSeventh> sevenths = new List <TSeventh>();
                cnn.Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TFirst>(provider.SqlString, (first, second, third, fourth, fifth, sixth, seventh) =>
                {
                    firsts.Add(first);
                    if (second != null)
                    {
                        seconds.Add(second);
                        if (third != null)
                        {
                            thirds.Add(third);
                            if (fourth != null)
                            {
                                fourths.Add(fourth);
                                if (fifth != null)
                                {
                                    fifths.Add(fifth);
                                    if (sixth != null)
                                    {
                                        sixths.Add(sixth);
                                        if (seventh != null)
                                        {
                                            sevenths.Add(seventh);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return(default(TFirst));
                }, provider.Params, transaction, true, splitOn);
                //分割导航属性数据
                firsts = ExcisionData(firsts, seconds, thirds, fourths, fifths, sixths, sevenths, navigationList);
                return(firsts);
            }
            else
            {
                return(cnn.Query <TFirst>(provider.SqlString, provider.Params, transaction));
            }
        }
示例#2
0
 /// <summary>
 /// 异步查询带聚合导航属性的对象集合
 /// </summary>
 /// <typeparam name="TFirst"></typeparam>
 /// <typeparam name="TSecond"></typeparam>
 /// <param name="cnn"></param>
 /// <param name="sql"></param>
 /// <param name="param"></param>
 /// <param name="transaction"></param>
 /// <param name="splitOn"></param>
 /// <returns></returns>
 public static async Task <TFirst> QueryFirstOrDefaultAsync <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(this IDbConnection cnn, SqlProvider provider, IDbTransaction transaction = null)
     where TFirst : IBaseEntity
     where TSecond : IBaseEntity
     where TThird : IBaseEntity
     where TFourth : IBaseEntity
     where TFifth : IBaseEntity
     where TSixth : IBaseEntity
     where TSeventh : IBaseEntity
 {
     return((await cnn.QueryAsync <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(provider, transaction)).FirstOrDefault());
 }
示例#3
0
 /// <summary>
 /// 查询带聚合导航属性的对象集合
 /// </summary>
 /// <typeparam name="TFirst"></typeparam>
 /// <typeparam name="TSecond"></typeparam>
 /// <param name="cnn"></param>
 /// <param name="sql"></param>
 /// <param name="param"></param>
 /// <param name="transaction"></param>
 /// <param name="splitOn"></param>
 /// <returns></returns>
 public static TFirst QueryFirstOrDefault <TFirst, TSecond, TThird, TFourth, TFifth, TSixth>(this IDbConnection cnn, SqlProvider provider, IDbTransaction transaction = null)
     where TFirst : IBaseEntity
     where TSecond : IBaseEntity
     where TThird : IBaseEntity
     where TFourth : IBaseEntity
     where TFifth : IBaseEntity
     where TSixth : IBaseEntity
 {
     return(cnn.Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth>(provider, transaction).FirstOrDefault());
 }
示例#4
0
        /// <summary>
        /// 查询带聚合导航属性的对象集合
        /// </summary>
        /// <typeparam name="TFirst"></typeparam>
        /// <typeparam name="TSecond"></typeparam>
        /// <param name="cnn"></param>
        /// <param name="provider"></param>
        /// <param name="transaction"></param>
        /// <param name="splitOn"></param>
        /// <returns></returns>
        public static IEnumerable <TFirst> Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth>(this IDbConnection cnn, SqlProvider provider, IDbTransaction transaction = null)
            where TFirst : IBaseEntity
            where TSecond : IBaseEntity
            where TThird : IBaseEntity
            where TFourth : IBaseEntity
            where TFifth : IBaseEntity
            where TSixth : IBaseEntity
        {
            EntityObject firstEntity = EntityCache.QueryEntity(typeof(TFirst));
            string       splitOn     = GetSplitOn <TFirst>(provider);

            if (!string.IsNullOrEmpty(splitOn))
            {
                //导航属性列表
                var navigationList = provider.JoinList.Where(x => x.Action == JoinAction.Navigation && x.IsMapperField).ToList();
                //把所有实体的信息存下做导航关联索引
                var firsts = new List <TFirst>();
                cnn.Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TFirst>(provider.SqlString, (first, second, third, fourth, fifth, sixth) =>
                {
                    var masterData = firsts.Find(x => x.GetId().Equals(first.GetId()));
                    //不存在的主表数据才添加进来,防止重复
                    if (masterData == null)
                    {
                        firsts.Add(first);
                        masterData = first;
                    }
                    //开始索引导航属性和之前实体的关系
                    if (second != null)
                    {
                        ExpressionExtension.SetProperValue(masterData, second, navigationList, 0);
                    }
                    if (third != null)
                    {
                        ExpressionExtension.SetProperValue(masterData, third, navigationList, 1);
                    }
                    if (fourth != null)
                    {
                        ExpressionExtension.SetProperValue(masterData, fourth, navigationList, 2);
                    }
                    if (fifth != null)
                    {
                        ExpressionExtension.SetProperValue(masterData, fifth, navigationList, 3);
                    }
                    if (sixth != null)
                    {
                        ExpressionExtension.SetProperValue(masterData, sixth, navigationList, 4);
                    }
                    return(default(TFirst));
                }, provider.Params, transaction, true, splitOn);
                return(firsts);
            }
            else
            {
                return(cnn.Query <TFirst>(provider.SqlString, provider.Params, transaction));
            }
        }
示例#5
0
        /// <summary>
        /// 异步查询带聚合导航属性的对象集合
        /// </summary>
        /// <typeparam name="TFirst"></typeparam>
        /// <typeparam name="TSecond"></typeparam>
        /// <param name="cnn"></param>
        /// <param name="provider"></param>
        /// <param name="transaction"></param>
        /// <param name="splitOn"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <TFirst> > QueryAsync <TFirst, TSecond, TThird, TFourth, TFifth, TSixth>(this IDbConnection cnn, SqlProvider provider, IDbTransaction transaction = null)
            where TFirst : IBaseEntity
            where TSecond : IBaseEntity
            where TThird : IBaseEntity
            where TFourth : IBaseEntity
            where TFifth : IBaseEntity
            where TSixth : IBaseEntity
        {
            EntityObject firstEntity = EntityCache.QueryEntity(typeof(TFirst));
            string       splitOn     = GetSplitOn <TFirst>(provider);

            if (!string.IsNullOrEmpty(splitOn))
            {
                //导航属性列表
                var navigationList = provider.JoinList.Where(x => x.Action == JoinAction.Navigation && x.IsMapperField).ToArray();
                var hashes         = new HashSet <TFirst>();
                cnn.Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TFirst>(provider.SqlString, (first, second, third, fourth, fifth, sixth) =>
                {
                    object id = first.GetId();
                    //判断当前主数据是否出现过
                    var lookup = hashes.FirstOrDefault(x => x.GetId().Equals(id));
                    if (lookup == null)
                    {
                        lookup = first;
                    }

                    ////设置导航属性对应
                    //if (second != null)
                    //	ExpressionExtension.SetProperValue(firstEntity, navigationList[0], second);
                    //if (third != null)
                    //	ExpressionExtension.SetProperValue(firstEntity, navigationList[1], third);
                    //if (fourth != null)
                    //	ExpressionExtension.SetProperValue(firstEntity, navigationList[2], fourth);
                    //if (fifth != null)
                    //	ExpressionExtension.SetProperValue(firstEntity, navigationList[3], fifth);
                    //if (sixth != null)
                    //	ExpressionExtension.SetProperValue(firstEntity, navigationList[4], sixth);

                    //不存在的主表数据才添加进来,防止重复
                    if (!hashes.Any(x => x.GetId() == lookup.GetId()))
                    {
                        hashes.Add(lookup);
                    }

                    return(default(TFirst));
                }, provider.Params, transaction, true, splitOn);
                return(hashes);
            }
            else
            {
                return(await cnn.QueryAsync <TFirst>(provider.SqlString, provider.Params, transaction));
            }
        }