Difference in linq-to-sql query performance using GenericRespositry

Posted by Neil on Stack Overflow See other posts from Stack Overflow or by Neil
Published on 2010-06-01T06:58:56Z Indexed on 2010/06/01 7:03 UTC
Read the original article Hit count: 267

Filed under:
|
|

Given i have a class like so in my Data Layer

public class GenericRepository<TEntity> where TEntity : class 
{
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
        public IQueryable<TEntity> SelectAll()
        {
           return DataContext.GetTable<TEntity>();
        }
}

I would be able to query a table in my database like so from a higher layer

using (GenericRepositry<MyTable> mytable = new GenericRepositry<MyTable>())
{
   var myresult = from m in mytable.SelectAll()
                  where m.IsActive
                  select m;
}

is this considerably slower than using the usual code in my Data Layer

using (MyDataContext ctx = new MyDataContext())
{
   var myresult = from m in ctx.MyTable
                  where m.IsActive
                  select m;
}

Eliminating the need to write simple single table selects in the Data layer saves a lot of time, but will i regret it?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ