这是我的表。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。对不起,请谅解 –
请将您的问题编辑。 (无论如何,我已经回答了,但是......) –