Why FirstOrDefault method aways gets all records from database?

The FirstOrDefault extension method work properly but it aways perform a sql query with no where clausule in database returning all records!

Thanks,

Vitor




Answer this question

Why FirstOrDefault method aways gets all records from database?

  • JoeyRelieved

    Simple. FirstOrDefault isn't handled by DLinq at the moment thus it is delegated to standard Linq functionality (it runs on all available records).

  • Pazu

    // This performs a SQL clausule with a where clausule

    // A exceptions it's returned when no results founded

    Enterprise enterprise = db.Enterprises.First(e => e.ID == 181);

    // This performs a SQL clausule with *NO* where clausule

    // All database records are internally returned

    Enterprise enterprise = db.Enterprises.FirstOrDefault(e => e.ID == 181);

    // This work ok

    Enterprise enterprise = db.Enterprises.Where(e => e.ID == 181).FirstOrDefault();



  • Ekta

    What is the query that you are trying to execute

  • Phil Nicholas

    That is an omission. The plan is to implement it in DLinq and not pull down all the records.

  • Why FirstOrDefault method aways gets all records from database?