【发布时间】:2021-02-17 04:26:30
【问题描述】:
// 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();
}
假设我在 using 范围内有一个复杂的 LINQ 结果。有没有办法让它逃到外面的世界?重点是匿名类型,在这种情况下我不会创建一个实际的类。
提前致谢。
【问题讨论】:
-
只是映射到自定义类对象?或将数据库上下文注入更大的范围,因此您不受使用块的限制
-
你最终得到了一个 toarray。您可以在使用外部使用数组类型的变量,然后分配结果。
-
你能展示你想用它做什么吗?
using与问题没有任何关系,因为您可以将其吊起来。 -
这完全取决于你想对数组做什么。
-
这可能就是你要找的 - stackoverflow.com/questions/6624811/…
标签: c# linq types scope anonymous-types