0

This is my table.

grp_perm_id   grp_id   Perm_id
23            2          2
27            2          1
28            3          1
29            2          3

I want to retrieve results in the form of array of integers. Below is the code I am trying

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();
}

Here I am receiving grp_id. For example if I receive 2(grp_id) then I want to return array of integers which contains perm_id (2,1,3). If the grp_id is 3 then array of integers contains perm_id(1). How can I do this? In the above code I am getting this error:

cannot implicitly convert type c3card.dal.edmodel.ts_grP_perm[] to int

Can anybody suggest me how to do this? I want to return array of integers.

This is my json code.

public JsonResult GetCheckedPerm(int usr_groupId)
{
    List<int> selectedradio = GrpPermBAL.GetData(usr_groupId);

    return(selectedradio,JsonRequestBehavior.AllowGet);
}
3
  • "i am getting error" is never enough information. What is the error? Compile-time or execution-time? Why are you calling ToArray twice? Commented Feb 3, 2016 at 11:08
  • cannot implicitly convert type c3card.dal.edmodel.ts_grP_perm[] to int. sorry for the inconvienience Commented Feb 3, 2016 at 11:11
  • Please edit that into your question. (I've answered anyway, but...) Commented Feb 3, 2016 at 11:12

1 Answer 1

1

You're currently selecting the whole row, rather than just the perm_id. You're also calling ToArray twice, and trying to return an array despite your method's return type being List<int>. I'd just use:

public List<int> GetData(int groupId)
{
    return db.ts_grp_perm_mapping
             .Where(c => c.grp_id == groupId)
             .Select(c => c.Perm_id)
             .ToList();
}

I've adjusted the name of the parameter to be more conventional - I'd strongly recommend that you adjust the property names (ts_grp_perm_mapping, grp_id, Perm_id) to be more conventional too.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes sure. This works fine. thank you. Actually i am calling this getdata function inside the json. I mentioned above my json code. in the last line when returning cannot convert lambda expresssion system.web.mvc.jsonresult because its not a delegate type
@LUTHFIABDULKADER: Well that's an entirely different matter, which you should research separately and ask a different question about, if you can't resolve it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.