C# LINQ to SQL: Refactoring this Generic GetByID method

前端 未结 6 1659
故里飘歌
故里飘歌 2020-11-30 02:03

I wrote the following method.

public T GetByID(int id)
{
    var dbcontext = DB;
    var table = dbcontext.GetTable();
    return table.ToList().Sin         


        
6条回答
  •  执笔经年
    2020-11-30 02:41

    What if you rework this to use GetTable().Where(...), and put your filtering there?

    That would be more efficient, since the Where extension method should take care of your filtering better than fetching the entire table into a list.

提交回复
热议问题