Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top