0

固定小数点からユーザーの位置を計算するLINQでUDFを使用する際にサポートが必要です。

int pointX = 567, int pointY = 534; // random points on a square grid
var q = from n in _context.Users 
join m in _context.GetUserDistance(n.posY, n.posY, pointX, pointY, n.UserId) on n.UserId equals m.UserId
select new User() {
  PosX = n.PosX,
  PosY = n.PosY,
  Distance = m.Distance,        
  Name = n.Name,
  UserId = n.UserId
};

GetUserDistanceは、TVPの単一の行を返すUDFであり、ユーザーはpointXおよびpointY変数で指定されたポイントからの距離を示し、デザイナーはそれに対して以下を生成します。

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetUserDistance", IsComposable=true)]
public IQueryable<GetUserDistanceResult> GetUserDistance([global::System.Data.Linq.Mapping.ParameterAttribute(Name="X1", DbType="Int")] System.Nullable<int> x1, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="X2", DbType="Int")] System.Nullable<int> x2, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Y1", DbType="Int")] System.Nullable<int> y1, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Y2", DbType="Int")] System.Nullable<int> y2, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="UserId", DbType="Int")] System.Nullable<int> userId)
{
    return this.CreateMethodCallQuery<GetUserDistanceResult>(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), x1, x2, y1, y2, userId);
}

コンパイルしようとすると、

The name 'n' does not exist in the current context
4

2 に答える 2

0

これは実際にはUDFの問題ではなく、LINQの問題です。句のソース部分で既存の範囲変数を使用することはできないため、joinこれも同様に間違っています。

string[] files = ...;
var query = from file in files
            join line in File.ReadAllLines(file) on file equals line
            ...

from代わりに、複数の句として記述する必要があると思います。

var q = from n in _context.Users 
        from m in _context.GetUserDistance(n.posY, n.posY, pointX, pointY, n.UserId)
        where n.UserId == m.UserId
        ...

参加が必要になるのは少し奇妙に思えますが、とにかくそのユーザーだけの結果になると期待するのはいつですか?GetUserDistanceこれは、次の場合により明確になる可能性があります。

var q = from n in _context.Users 
        let m = _context.GetUserDistance(n.posY, n.posY, pointX, pointY, n.UserId)
                        .Single()
        ...
于 2012-09-25T09:41:00.450 に答える
0

参加する必要はないと思います。これを試してください。

int pointX = 567, int pointY = 534; // random points on a square grid
var q = from n in _context.Users 
let m = _context.GetUserDistance(n.posY, n.posY, pointX, pointY, n.UserId).Single()
select new User() {
    PosX = n.PosX,
    PosY = n.PosY,
    Distance = m.Distance,        
    Name = n.Name,
    UserId = n.UserId
};
于 2012-09-25T09:44:38.150 に答える