从对象类型System.Data.SqlClient.SqlParameter []到已知的托管提供程序本机类型不存在映射

时间:2017-08-07 10:42:03

标签: c# entity-framework

这是我的代码和字符串值包含传递的数据,“temp”包含存储在字符串数组中的数据的no。然后将数据存储在sqlparameter对象中,然后作为SqlQuery中的对象传递:

    public List<T> updateSiteDetails<T>(int SiteId, int CategoryId, string[] values)
    {
        int temp = values.Count()+1;
        int Counter = 0;


        SqlParameter[] sParams = new SqlParameter[temp]; // Parameter count
        sParams[0] = new SqlParameter();
        sParams[0].SqlDbType = SqlDbType.Int;
        sParams[0].ParameterName = "@SiteId";
        sParams[0].Value = SiteId;

        sParams[1] = new SqlParameter();
        sParams[1].SqlDbType = SqlDbType.Int;
        sParams[1].ParameterName = "@CategoryId";
        sParams[1].Value = CategoryId;

        for (int i = 2,j=1; i < temp;i++,j++)
        {
            sParams[i] = new SqlParameter();
            sParams[i].SqlDbType = SqlDbType.NVarChar;
            sParams[i].ParameterName = "@value"+j;
            sParams[i].Value = values[j];
        }
        object[] parameters=new object[]{sParams};

        List<T> SiteDetails = null;
        using (SBDEntities db = new SBDEntities())
        {
            SiteDetails = db.Database.SqlQuery<T>("Sp_Update_AppData", parameters).ToList();//error is here
            return SiteDetails;
        }
    }

0 个答案:

没有答案