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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:23+00:00 2026-06-01T20:03:23+00:00

Hi I have this bit of linq code var fp = lnq.attaches.First(a => a.sysid

  • 0

Hi I have this bit of linq code

var fp = lnq.attaches.First(a => a.sysid == sysid).name;

When profiled it generates the following t-sql

SELECT TOP (1) [t0].[sysid], [t0].[name], [t0].[att_size], [t0].[cid], [t0].[flags], [t0].[contents] 
FROM [lntmuser].[attach] AS [t0]

The way I look at it, it is returning like a select *, which will cause the query to perform a table scan rather then use an index. Bad for performance.

How could I select just the name column, like:

SELECT TOP (1)[t0].[name] FROM [lntmuser].[attach] AS [t0]

Thanks in advance


Edit:
Broken Glasses Solution profiles as desired

SELECT TOP (1) [t0].[name]
FROM [lntmuser].[attach] AS [t0]
WHERE [t0].[sysid] = @p0
  • 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-01T20:03:24+00:00Added an answer on June 1, 2026 at 8:03 pm

    Project to the name property before using First():

    var fp = lnq.attaches.Where(a => a.sysid == sysid)
                         .Select(a => a.name)
                         .First();
    

    This doesn’t change the use of an index though – for that your Where clause is responsible (in your initial query the lambda you passed to First()). Both queries benefit from an index on the name column, the second one is just faster because only one column value has to be materialized.

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

Sidebar

Related Questions

I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I use this bit of code to feed some data i have parsed from
its a little bit hard to understand. in the header.php i have this code:
Yesterday I wrote the following c# code (shortened a bit for legibility): var timeObjects
I have a bit of linq to entities code in a web app. It
I have this bit of code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
This is for .NET 2.0, so I cannot use LINQ. I have a bit
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
I have this small snippet to change a bit of html when a user

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.