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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:53:12+00:00 2026-05-10T16:53:12+00:00

I have created some extra functionality on my Linq-to-SQL classes to make things easier

  • 0

I have created some extra functionality on my Linq-to-SQL classes to make things easier as I develop my applications. For example I have defined a property that retrieves active contracts from a list of contracts. However if I try to use this property in a lambda expression or in general in a query it either throws an exception that there is no SQL statement matching that property or it generates one query per item (= a lot of roundtrips to the server).

The queries themselves are not overly complex f.ex:

var activeContracts = customer.Contracts.Where(w => w.ContractEndDate == null); 

Whereas I would like it to read as:

var activeContracts = customer.ActiveContracts; 

The main reason for me doing this is because it will minimize logical errors on my part and if I in the future want to change what defines an active contract I don’t have to redo a lot of code.

Is there a way to specify on a property what SQL it should genereate. Or is there a way to make sure it is usable in a query like below?

var singleContractCustomers = db.Customers.Where(w => w.ActiveContracts.Count() == 1); 
  • 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. 2026-05-10T16:53:13+00:00Added an answer on May 10, 2026 at 4:53 pm

    When accessed individually, I suspect that having a query that returns IQueryable would work – however, I expect that when this is part of a larger Expression, the expression interpreter will complain (which seems like what you are describing).

    However, I suspect that you might be able to break it down a bit. Try adding (to customer):

        public static Expression<Func<Customer, bool>> HasActiveContract     {         get { return cust => cust.Contracts.Count() == 1; }     } 

    Then you should be able to use:

        var filtered = db.Customers.Where(Customer.HasActiveContract); 

    Obviously it is hard to run it (from here) to see what TSQL it comes up with, but I’d be surprised if that does roundtrips; I would expect that to do the COUNT() in the TSQL. As a topmost query, you should also be able to wrap this:

        public IQueryable<Customer> CustomersWithActiveContract     {         get { return Customers.Where(Customer.HasActiveContract); }     } 

    Does any of that work?

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think what you're looking for is: sqlite x.db .dump… May 11, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer There are flags in the PE that indicate managed code.… May 11, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer Yes, there is a way to do it in XPath… May 11, 2026 at 7:50 pm

Related Questions

The desired functionality of the 'enhanced' combo box is a quick find method. Each
I have subclassed Form to include some extra functionality, which boils down to a
Background I work for a large organization which has thousands of MS Access applications
I'm trying to learn the new ASP .NET MVC framework and would like to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.