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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:57:07+00:00 2026-05-25T17:57:07+00:00

I am using Linq extensively in my project, so far performance is good, i

  • 0

I am using Linq extensively in my project, so far performance is good, i have just one doubt if i have used Linq something like this

var getData = objData.where(obj => obj.isDelete ==false)
if (getData != null && getData.Count() > 0)
   foreach(xyz as obj in getdata.ToList())
   {
      //some operation
   }

Does getData.Count() and getdata.ToList() performs two different fetches on object? Or as per deffer loading concept when getData.Count() is executed then no operation is performed for .ToList.

If not then should i remove Count condition, will it improve the performance?

I am using Enterprise Library 5.0 acessor methods to get data from DB
List lstpack = new List();

            var accessor = _sqlDatabase.CreateSprocAccessor<PackageForClient>("PackageForClientApp", MapBuilder<PackageForClient>
                      .MapAllProperties()
                      .Build()
               );

            var Data = accessor.Execute(startdate, enddate,beinh);
            if (Data != null) //&& Data.Count() > 0 //This has been removed as it is doing an extra fetch
                lstpack = Data.ToList<PackageForClient>();

Now returning the list

  • 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-25T17:57:08+00:00Added an answer on May 25, 2026 at 5:57 pm

    It’s hard to say for sure, as we don’t know what getData is, but:

    • Yes, potentially they’ll be completely separate operations
    • In general, use Any() instead of Count() > 0; it can be a lot more efficient, particularly in LINQ to Objects
    • Calling ToList is going to be relatively cheap when it’s empty – just do it if you need a list
    • If you don’t really need it in a list, just iterate anyway (if there’s no data, you’ll never get into the loop body)
    • Where will never return null

    In other words, I’d probably write:

    foreach (Obj xyz in objData.Where(obj => !obj.isDelete))
    {
       //some operation
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using linq and you have c.Sort() Is there any good inline way of
I'm using linq-to-sql for a query like this: public static List<MyModel> GetData(int TheUserID, DateTime
I am using Linq like this: IQueryable<Rentals> rentals = from r in context.Rentals select
using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to
using LINQ to XML, this is a sample of my XML <shows> <Show Code=456
Im using LINQ over DataSet but just to get data from some tables, by
I´m using linq to sql and I have a lot of tables with foreign
Using linq to sql I would like to generate some sealed classes in a
Using LINQ I would like to retrieve all files under a given directory that
Using linq? and XML is there a way to convert this IEnumerable to a

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.