Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:05:30+00:00 2026-06-11T20:05:30+00:00

I need help using a UDF in a LINQ which calculates a users position

  • 0

I need help using a UDF in a LINQ which calculates a users position from a fixed point.

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
};

The GetUserDistance is just a UDF that returns a single row in a TVP with that users distance from the points deisgnated in pointX and pointY variables, and the designer generates the following for it:

[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);
}

when i try to compile i get

The name 'n' does not exist in the current context
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:05:31+00:00Added an answer on June 11, 2026 at 8:05 pm

    This isn’t really a UDF problem – it’s a LINQ problem. You can’t use an existing range variable in the source part of a join clause, so this would be equally wrong:

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

    I suspect you’ll need to write it as multiple from clauses instead:

    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
            ...
    

    Although it seems slightly odd to need a join at all, when I’d expect the results of GetUserDistance to only be for that user anyway, right? This might be clearer with:

    var q = from n in _context.Users 
            let m = _context.GetUserDistance(n.posY, n.posY, pointX, pointY, n.UserId)
                            .Single()
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
We are using Linq-to-SQL with stored Procedures we need help on one of our
I need help reviewing a basic tooltip using jQuery ui position. The jQuery tooltip
Need help with deleting call log from multi numbers, using the following code i
I need help to pull RSS feeds from a facebook page I'm using the
I need help fetching tree hierarchy from db using nhibernate 3.0 QueryOver.Of<Enterprise>(() => entAlias)
I need help with using a normal SQL LIKE %% operator within a LINQ
Need help in updating records using LinQ. I tried updating the record, but it
I need some help using LINQ to filer a list of files based on
I need some help in using objects from Core Data with GCD; I seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.