Compare the performance of two different LINQ statements

I am learning C # (background in C ++) and I have a question about LINQ expressions. The following two functions perform the same thing (as far as I can tell). Type Wombats System.Data.Linq.Table<Wombat>.

I'm interested to know

  • Which is more efficient?
  • Does it even matter?
  • Is there anything I can get by returning IQueryqble?
  • Is there any etiquette that prefers one of the three?

My hunch is that the second is more efficient, but that doesn't really matter if there aren't millions of wombats in the wombat table. And returning IQueryable doesn't seem to make much difference, since we only return one wombat.

Thanks in advance!

    public static DBConnector.Connections.Wombat getWombat(String wombatID)
    {
        var db = getDBInstance();
        return db.Wombats.FirstOrDefault(x => x.ID.ToString() == wombatID);
    }

    public static DBConnector.Connections.Wombat getWombat(String wombatID)
    {
        var db = getDBInstance();
        var guid = new System.Guid(wombatID);
        return db.Wombats.FirstOrDefault(x => x.ID == guid);
    }
+5
source share
4 answers

DB LINQ SQL. SQL ( SQL) , .

, , - . , , . , .

+7

, , , , GUID , GUID . , ; , GUID , .

, , , Wombat.

: ToString , - .

+5
  • sql .
  • , IO sql.
  • ???
  • Profit.
+3

IQuerable, , - .

+1

All Articles