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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:47:00+00:00 2026-06-09T17:47:00+00:00

using linq, I want to check if a row exist on the DB. I

  • 0

using linq, I want to check if a row exist on the DB. I just need a true\false return, no data.
I cant use the ExecuteQuery method because I dont have an entity (and I dont even need it)
I thought of doing something like this:

string command = "select * from myTable where X=Y"
var result = db.ExecuteCommand(command);

(db is my DataContext)
and expected the result to contain the number of affected rows. If different that -1 it would mean the record I’m looking for exists. But I always get -1. I imagine the ExecuteCommand method should only be used to tu run Insert, updates or deletes.

How can I run this simple check using linq

  • 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-09T17:47:01+00:00Added an answer on June 9, 2026 at 5:47 pm

    If db is your data context, you should just do:

    bool rowExists = dc.GetTable<myTable>().Any(row => row.X == row.Y);
    

    In general, with LINQ to SQL (and Entity Framework), you rarely want to write SQL code directly.

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

Sidebar

Related Questions

I want to make custom select from the database table using Linq. We use
I want to check whether a string is palindrome or not using Linq. Updated:
I want to check for duplicates in Entity Framework using Linq-To-Entities, ignoring cases. What's
I want to using Linq to help make a list of movies an actor
I'm using LINQ to Entities and I want to know how do I translate
I'm using Linq to SQL to access my database. I want to have a
I have following LINQ statement and I want to rewrite it using extension methods.
I am using WCF to send some Linq objects across the wire. I want
using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to
Using Linq to Entities, I have an IQueryable<T> and want to add another WHERE

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.