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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:58:14+00:00 2026-06-11T04:58:14+00:00

I am working with LINQ and MS SQL using c#. I am facing a

  • 0

I am working with LINQ and MS SQL using c#. I am facing a problem in fetching records. I have 2 tables as,
Sales
Transactions
Sales primary key is being referred by Transactions table.Data is like,
enter image description here

What I am trying to do is to fetch all the records with amount != 0. In this example, the result should include only Sales2 and Sales3, but not Sales1. Since Sales1 is closed.

I have written a query like,

List<Sales> lstSales = (from ccs in context.Sales
                        join transactions in context.Transactions 
                             on ccs.SALESID equals  transactions.SALESID            
                        where transactions .AMOUNT !=0 
                       select ccs).ToList();

It returns me all the 3 Sales records, because for 1 row against Sales1, amount !=0.

Please guide me to achieve the desired results.

Thanks in advance,
Vijay

  • 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-11T04:58:16+00:00Added an answer on June 11, 2026 at 4:58 am

    Though your query filter out the closed transactions, still you have > 0 transactions in the result so you still get the Sales1 Id.

    Try this instead (it should work, though I haven’t tested this);

    IEnumerable<int> closedIds = context.Transactions.Where(t => t.Amount == 0).Select(t=> s.SalesId);
    List<Sales> sales = context.Sales.Where(s => !closedIds.Contains(s.SalesId));
    

    Another approach is (assuming you have an association between Sales and Transaction in the context);

    List<Sales> sales = context.Sales.Where(s => !s.Transactions.Any(t=> t.Amount == 0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using Linq to SQL for a project im working on and
I'm using Linq-To-SQL for a project with around 75 tables. We have to keep
We have a project using LINQ to SQL, for which I need to rewrite
I'm looking at using LINQ to SQL for a new project I'm working on,
I have implemented a custom membership provider using LINQ to SQL. When I added
I have been working with NHibernate, LINQ to SQL, and Entity Framework for quite
I have a method where I execute a query SQL (I'm using Linq to
I'm working in Visual Studio 2010 using linq-to-sql's DataContext which has several maps to
I have been looking at making the switch from SQL TableAdapters to Linq using
I am working on a 3-Tier application. Also I am using LINQ to SQL

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.