LinqHelp需要从sql模型转换为LinqObject模型

本文关键字:模型 转换 LinqObject sql LinqHelp | 更新日期: 2023-09-27 18:27:44

我有以下Linq,

from x in Enumerable.Range(refx - 1, 3)
from y in Enumerable.Range(refy - 1, 3)
where
  (x >= 0 && y >= 0) &&
  (x < array.GetLength(0) && y < array.GetLength(1)) &&
  !(x == refx && y == refy)
select new Location(x,y)

我想在其他Linq格式的中有相同的

类似

Enumerable.Range(refx-1,3)
.Select(x)
.Range(refy - 1, 3)
.Select(y)
.Where(x >= 0 && y >= 0) &&
      (x < array.GetLength(0) && y < array.GetLength(1)) &&
      !(x == refx && y == refy)
.Select new Location(x,y)

我知道上面的是错误的,但我想要第秒格式的第一个,非常重视任何帮助

同样,如果有人擅长linq.js,将第一个转换为linqjs将是非常棒的!

LinqHelp需要从sql模型转换为LinqObject模型

我想Zip就是您想要的。

Enumerable.Range(refx - 1, 3).Zip(Enumerable.Range(refy - 1, 3),
    (x, y) => new Tuple<int, int>(x, y))
    .Where(t => (t.Item1 >= 0) && (t.Item2 <= 0)
    && (t.Item1 < array.GetLength(0)) && (t.Item2 < array.GetLength(1))
    && !((t.Item1 == refx) && (t.Item2 == refy)))
    .Select(t => new Location(t.Item1, t.Item2));

这相当于:

    var set = Enumerable.Range(refx - 1, 3)
            .Select(x => Enumerable.Range(refy - 1, 3)
                .Where(y => (x >= 0 && y >= 0) &&
                    (x < array.GetLength(0) && y < array.GetLength(1)) &&
                    !(x == refx && y == refy))
                .Select(y => new Location(x, y)))
            .SelectMany(x => x);