0
// var outterResult = null;

using (var ctx = new TIS2APPContext())
{
    var results = (
        from t in (
            from route in ctx.ROUTEs
            join rstop in ctx.RSTOPs on route.ROUTEID equals rstop.ROUTEID
            join stop in ctx.STOPs on rstop.STOPID equals stop.STOPID
            select new { Route = route, RStop = rstop, Stop = stop }
        ).ToArray()
        group new { RStop = t.RStop, Stop = t.Stop } by t.Route into g
        select new { Route = g.Key, Stops = g.ToArray() }
    ).ToArray();
}

Let say I have a complicated LINQ results in a using scope. Is there a way to get it escape to the outside world? The point is anonymous type, I am not going to create an actual class in this case.

Thanks in advance.

mannok
  • 1,712
  • 1
  • 20
  • 30

1 Answers1

0

You can not declare type for anonymous object, but you can give it a hint if you use anonymous objects with the same fields in the outer scope. Fields can have dummy values.

You are still limited to a scope of the executing method, though. To use it outside of the method you'll need to map result to tuples, if you don't want to use classes

var results = new[]
{
    new { Route = string.Empty, Stops = new List<string>() }
};

using (var db = new DbContext(""))
{
    results = (from o in db.Set<object>()
                    select new { Route = string.Empty, Stops = new List<string>() }
                    ).ToArray();
}
Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40