示例#1
0
        public static DbParameter[] BuildDbParameters <T>(string cmdText, T entity, Func <DbParameter> dbParamConstructor, InputMap <T> map, char sqlParamSplitter)
            where T : class
        {
            List <string> list = Analyst.GetSqlParamNameList(cmdText);
            List <ParameterProperty <T> > maps = (map == null) ? null : map.GetMaps();

            if (maps == null)
            {
                maps = new List <ParameterProperty <T> >(0);
            }
            List <DbParameter> pList = new List <DbParameter>(list.Count);

            foreach (string pName in list)
            {
                DbParameter parm = dbParamConstructor();
                parm.ParameterName = pName;
                ParameterProperty <T> pp = maps.Find(p => p.Parameter == pName);

                string[] proArray;
                if (pp != null)
                {
                    proArray = pp.PropertyList.ToArray();
                }
                else
                {
                    proArray = pName.Split(sqlParamSplitter);
                }
                object tmp = GetFieldValueAllowNull(entity, proArray);
                parm.Value = (tmp == null ? DBNull.Value : tmp);
                pList.Add(parm);
            }
            return(pList.ToArray());
        }
示例#2
0
        public InputMap <T> Add(string parameterName, Expression <Func <T, object> > expression)
        {
            if (m_List.Exists(p => p.Parameter == parameterName))
            {
                throw new ApplicationException("SQL参数" + parameterName + "重复设置");
            }

            ParameterProperty <T> pc = new ParameterProperty <T>();

            pc.Parameter          = parameterName;
            pc.PropertyCombineStr = Analyst.GetPropertyCombineStr(expression.Body);
            //pc.PropertyGetter = expression.Compile();
            m_List.Add(pc);
            return(this);
        }
示例#3
0
        public ReturnMap <T> Add(Expression <Func <T, object> > expression, string columName)
        {
            string proCombineStr = Analyst.GetPropertyCombineStr(expression.Body);

            if (m_List.Exists(p => p.PropertyCombineStr == proCombineStr))
            {
                throw new ApplicationException("属性" + proCombineStr + "重复设置");
            }
            PropertyColumn pc = new PropertyColumn();

            pc.PropertyCombineStr = proCombineStr;
            pc.Column             = (columName == null || columName.Trim().Length <= 0) ? proCombineStr : columName;
            m_List.Add(pc);
            return(this);
        }