Exemplo n.º 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());
        }
Exemplo n.º 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);
        }