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 6918853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:54:46+00:00 2026-05-27T09:54:46+00:00

I have a LINQ to SQL class, we’ll call it Test , and I

  • 0

I have a LINQ to SQL class, we’ll call it Test, and I want to be able to access properties with LINQ queries but I get the famed “No Supported Translation to SQL” runtime error. I’m interested in the conceptual problem. Here is my simplified class:

public class Test
{ 
  public int ID {get; set;} // Stored in Database
  public int NonForeignKeyValue {get; set;} // Stored in Database
}

Here is sort of an example of what I’m trying to accomplish, but I don’t want the overhead of always explicitly writing the join in LINQ:

var db = (new DataContext()).GetTable<Test>();
var q = (from t in db.GetTable<Test>()
         join o in db.GetTable<OtherTable>() on o.ID equals t.ID
         where t.OtherStuff
         select t)

I’d like to be able to add a property to Test that tells me if there are any rows in OtherTable that could be joined with Test:

  public bool IsInOtherTable
  {
    get
    {
       return (new DataContext())
              .GetTable<OtherTabke>()
              .Any(x => x.NonForeignKeyValue == this.NonForeignKeyValue));
    }
  }

Ultimately this is what I want my code to look like, but it errors. I basically want to return all entries that contain some database computed value:

using (DataContext db =  new DataContext())
{
   var q = db.GetTable<Test>()
             .Where(x => x.IsInOtherTable && x.OtherStuff); //Error
}       

I’m basically trying to save myself from writing this code every single time I want to check if Test has certain information in another table. I’m not that interested in the exact problem I described, I’m more interested in how to conceptually add the join part to the SQL and still use LINQ. I’m guessing I use Linq.Expression, but I really don’t know and I’m not aware of how to do it.

As an aside, I could just write the actual SQL, as its not that complicated, but I’d like to know how to get around this and still use LINQ.

Edit: I tried this property, but I get the same error. Its more complicated that just changing the return type to Expression…

public System.Linq.Expressions.Expression<Func<Article3, bool>> Exists
{
    get
    {
       using (DataContext db =  new DataContext())
       {
         return i => db.GetTable<OtherTable>()
                       .Any(x => x.NonForeignKeyValue == i.NonForeignKeyValue));
       }
    }
}        
  • 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-05-27T09:54:47+00:00Added an answer on May 27, 2026 at 9:54 am

    Firstly, I think you may be overestimating “the overhead of always explicitly writing the join in LINQ”. It’s an extra line of code which has the advantage of being relatively self-documenting as to just what you are doing (always a nice thing), and any other approach is going to be turned first into SQL and then into a query plan that will be at least as expensive to execute, possibly more expensive (SQLServer is good a joins!)

    Still, there are two alternatives I can thinkof.

    One is to have an EntityRef property on the class that defines this relationship with the other table. You can then test if it is null in your query (or EntitySet if it’s on the other side of a one-to-many relationship).

    The other is to define a SQL function that returns a bit result indicating whether an id refers to a row that does or doesn’t relate to the other table.

    Then define a protected method on your DataContext-derived class that matches the signature in C# terms, and has a Function attribute mapping it to that SQL function. (Since this isn’t something that you can give a sensible non-db-using version of in the C# version, you can implement the C# function by calling ExecuteMethodCall).

    Then you can use that method instead of the join.

    Still, this is likely less self-explanatory in the code and at risk of being less efficient than just keeping the join.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linq to sql class with several table bound properties, but I
I have a class which provides generic access to LINQ to SQL entities, for
Suppose I have a linq to sql class. I want to return the object
I have a Linq-to-SQL class, and I'd like to perform some pre-save validation before
I have a LINQ to SQL class VoucherRecord based on a simple table. One
I have a LINQ to SQL generated class with a readonly property: <Column(Name:=totalLogins, Storage:=_TotalLogins,
What I have: LINQ to SQL auto generated class, which corresponds to the shape
I have a Linq-To-Sql based repository class which I have been successfully using. I
I have a class containing Linq To SQL objects that are used to populate
Using LINQ to SQL, I have an Order class with a collection of OrderDetails.

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.