Пример #1
0
        public bool Fill <T>(object obj, string table, Dictionary <string, object> attachedWhere) where T : class, new()
        {
            SqlExpressionArgs args = new SqlExpressionArgs();

            args.Table = table;
            args.Type  = SqlExpressionType.Select;
            if (attachedWhere == null)
            {
                args.GenerateWhere = true;
            }
            else
            {
                args.GenerateWhere = false;
                args.AttachedWhere = AttachedWhereItem.Parse(attachedWhere);
            }

            //不能用 default(T) ,会是null
            SqlExpression sqlExpression = RelationalMappingUnity.GetSqlExpression(obj, args);

            DataSet  ds       = ExcuteDataSetSqlExpression(sqlExpression);
            List <T> dataList = RelationalMappingUnity.Select <T>(ds.Tables[0]);

            Debug.Assert(dataList.Count <= 1, "Fill 时取出的记录大于1条");

            if (dataList.Count != 1)
            {
                return(false);
            }

            T dataObj = dataList[0];

            ReflectionHelper.Inject(obj, dataObj);

            return(true);
        }
Пример #2
0
        public static List <AttachedWhereItem> Parse(Dictionary <string, object> attachedWhere)
        {
            List <AttachedWhereItem> list = new List <AttachedWhereItem>();

            if (attachedWhere == null || attachedWhere.Count == 0)
            {
                return(list);
            }

            foreach (var item in attachedWhere)
            {
                AttachedWhereItem attachedWhereItem = new AttachedWhereItem();
                attachedWhereItem.Field = item.Key;
                attachedWhereItem.Value = item.Value;
                list.Add(attachedWhereItem);
            }

            return(list);
        }
Пример #3
0
 public List <T> Select <T>(Dictionary <string, object> attachedWhere, SqlExpressionPagingArgs pagingArgs) where T : class, new()
 {
     return(Select <T>(AttachedWhereItem.Parse(attachedWhere), pagingArgs));
 }
Пример #4
0
 public List <T> Select <T>(Dictionary <string, object> attachedWhere) where T : class, new()
 {
     return(Select <T>(AttachedWhereItem.Parse(attachedWhere), null));
 }