Asp.net mvc 实体vs DataContext.GetTable<;实体>;

Asp.net mvc 实体vs DataContext.GetTable<;实体>;,asp.net-mvc,linq-to-sql,repository,Asp.net Mvc,Linq To Sql,Repository,我正在ASP.NET MVC应用程序中实现存储库“模式”。所以我读了一些书,决定是公开整个DataContext(在构造函数中初始化),还是只通过.GetTable公开表,因为性能是最重要的因素 在进行谷歌搜索时,我在上遇到了以下代码。在这段代码中,他首先取出表,然后查询该对象。所以现在我想知道这种方法是否有好处 public void PrintWinners() { // creates a data context that takes the path of the databas

我正在ASP.NET MVC应用程序中实现存储库“模式”。所以我读了一些书,决定是公开整个DataContext(在构造函数中初始化),还是只通过.GetTable公开表,因为性能是最重要的因素

在进行谷歌搜索时,我在上遇到了以下代码。在这段代码中,他首先取出表,然后查询该对象。所以现在我想知道这种方法是否有好处

public void PrintWinners()
{
   // creates a data context that takes the path of the database
   DataContext dc = new DataContext(@"C:\Program Files\
      Microsoft SQL Server\MSSQL.1\MSSQL\Data\UCL.mdf");

   // retrieves a Table of Winner
   Table<Winner> winners = dc.GetTable<Winner>();

   // creates a sequence of winners ordered descending by the
   // winning year
   var result = from w in winners
                orderby w.Year descending
                select w;

   // prints the sequence of winners
   foreach (var w in result)
   {
      Console.WriteLine("{0} {1}, {2}",
      w.Year, w.Name, w.Country);
   }
}
public void PrintWinners()
{
//创建采用数据库路径的数据上下文
DataContext dc=新的DataContext(@“C:\Program Files\
Microsoft SQL Server\MSSQL.1\MSSQL\Data\UCL.mdf”);
//检索赢家表
表winners=dc.GetTable();
//创建按顺序递减的赢家序列
//获胜年份
var结果=来自winners中的w
按w.年递减排序
选择w;
//打印获奖者的顺序
foreach(结果中的var w)
{
Console.WriteLine(“{0}{1},{2}”,
w、 年份,w.姓名,w.国家);
}
}

要使存储库具有足够的通用性,以便在所有应用程序中使用,唯一的方法是使用

DataContext.GetTable<Entity>
DataContext.GetTable

DataContext.EntityName由标准t4模板生成,是最不可扩展的选项。

好吧,暂时不要考虑存储库部分。生成的DataContext.MyEntity调用GetTable的2@Fabian Nope在性能方面有什么不同吗