Difference in linq-to-sql query performance using GenericRespositry
- by Neil
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?