這是我的表。Linq查詢以int數組的形式獲取查詢結果
grp_perm_id grp_id Perm_id
23 2 2
27 2 1
28 3 1
29 2 3
我想以整數數組的形式檢索結果。以下是我正在嘗試的代碼
public List<int> GetData(int grp_id)
{
// List<ts_grp_perm_mapping> tm = (from c in db.ts_grp_perm_mapping where c.grp_id == grp_id select c).ToList();
int[] selectedradiobuttons = (from c in db.ts_grp_perm_mapping where c.grp_id == grp_id select c).ToArray();
return selectedradiobuttons.ToArray();
}
這裏我收到grp_id。例如,如果我收到2(grp_id),那麼我想返回包含perm_id(2,1,3)的整數數組。如果grp_id是3,則整數數組包含perm_id(1)。我怎樣才能做到這一點?在上面的代碼中,我得到這個錯誤:
cannot implicitly convert type c3card.dal.edmodel.ts_grP_perm[] to int
有人可以建議我該怎麼做?我想返回整數數組。
這是我的json代碼。
public JsonResult GetCheckedPerm(int usr_groupId)
{
List<int> selectedradio = GrpPermBAL.GetData(usr_groupId);
return(selectedradio,JsonRequestBehavior.AllowGet);
}
「我越來越錯誤」是*從來沒有*足夠的信息。什麼是錯誤?編譯時間還是執行時間?你爲什麼要兩次調用ToArray? –
不能將類型c3card.dal.edmodel.ts_grP_perm []隱式轉換爲int。對不起,請諒解 –
請將您的問題編輯。 (無論如何,我已經回答了,但是......) –