SqlParameter[] parms = new SqlParameter[2];
SqlParameter id = new SqlParameter("ID", "11a44466-6d9c-4c7e-b9e4-5a1369061119");
id.SqlDbType=SqlDbType.NVarChar;
id.Size = 128;
parms[0] = id;
var outParam = new SqlParameter();
outParam.ParameterName = "Name";
outParam.SqlDbType = SqlDbType.VarChar;
outParam.Size = 64; //必須填寫正確,否則會有這種異常:{"String[1]: the Size property has an invalid size of 0."}
outParam.Direction = ParameterDirection.Output;
parms[1]=outParam;
//當有這樣異常時,"... A member of the type ... does not have a corresponding column in the data reader with the same name"
//是存儲過程返回的字段名與對應Model的屬性名對不上, 解決加法是在存儲過程中取別名與Model的屬性同名
var result = db.Database.SqlQuery<Category>("P_GetCategoryByID @ID,@Name output", parms);
string title = outParam.Value as string;