0

Finally find in first solution how to generate related filter selects for a jqGrid... but now I'm wondering how generate this statesOfCountry JavaScript array in my MVC 4 app using using EF 6.1.

I'm assuming that linq will help to get something like this on my MVC controller:

var rel_man_lin =
(
    from f in db.Products
    select new
       {
          f.IdMaufacture,
          line = new [] {
             from l in db.Lines 
             where f.Relation.IdLine == l.IdLine
             select l.IdLine
          }.Single()
       }
).Distinct();
ViewData["rel_fab_lin"] = rel_fab_lin;

To finally set on my scripts region on my view this:

var ls = [@ViewData["rel_fab_lin"]];

It should be like this or exists some other way?

Thanks!

Community
  • 1
  • 1
  • So what you have done has worked? –  Apr 18 '14 at 18:59
  • No, at this moment I'm have some alternative to move array data to view... but don't have idea of linq sentence to generate something like this: var statesOfCountry = { 1: { '1': 'Alabama', '2': 'California', '3': 'Florida', '4': 'Hawaii' }, 2: { '5': 'London', '6': 'Oxford' } }; – Carlos Mosquera Apr 21 '14 at 14:29
  • Looks like will need C# jagged array and a way to transfer into view. – Carlos Mosquera Apr 21 '14 at 15:34

1 Answers1

0

You can try this way just an example:

        var rel_man_lin= db.Products.GroupJoin(db.Lines,
        p => p.Relation.IdLine,
        l => l.IdLine,
(p, result) => new Result(p.IdMaufacture, result));

// Test the Enumerate results to see if it meets your expectation foreach (var result in rel_man_lin) { Console.WriteLine("{0} contains...", result.IdMaufacture); foreach (var item in result.ListOfState) { Console.WriteLine("{0} {1}",item.IdofState, item.NameOfstate); } } Please note that .ListOfState, .NameOfstate and IdofState don't exist but just to express the idea behind the query as you want result to be formatted as an Id and a collection.

I hope it will help you.