コード例 #1
0
        public IQueryable <T> CallStored <T>(string _storedName, object _params) where T : class
        {
            List <MySqlParameter> lst = null;
            string query = $"CALL {_storedName}";

            if (_params != null)
            {
                lst = new List <MySqlParameter>();
                PropertyInfo[] props = _params.GetType().GetProperties();
                string         prs   = "";
                foreach (var prop in props)
                {
                    prs += "@" + prop.Name + ",";
                    MySqlParameter param = new MySqlParameter("@" + prop.Name, prop.GetValue(_params));
                    lst.Add(param);
                }
                query += $"({prs.Trim(',')})";
            }
            var item = context
                       .Query <T>()
                       .FromSql($"{query}", lst.ToArray());

            return(item);
        }