建立連接,當你打的SubmitChanges(如果有要進行更改)。我不知道,如果在上面的代碼中只有一個連接被打開和使用,但我知道在我提到的兩個地方,你會調用連接。
您需要開始查看LinqPad和how to use it而不是dimecasts。還檢查了他們的一系列關於Delayed Execution features of Linq 2 Sql
注意,這樣的事情(getTenSomethingElse(S,S,S))不查詢數據庫,至少直到你開始列舉了返回值
partial class MyDataContext
{
// builds the tree to pull data from the db that matches a criteriea and pass it a ctor of another class
public System.Linq.IQueryable<SomethingElse> getSomethingElse(string searchTerm, string searchValue, string orderBy)
{
var items =
from s in
this.Somethings
select new SomethingElse(s);
return items.Where(searchTerm, searchValue).OrderBy(orderBy);
}
// calls the above method but adds take 10 to that tree
public System.Linq.IQueryable<SomethingElse> getTenSomethingElse(string searchTerm, string searchValue, string orderBy)
{
var items =
from s in
this.getSomethingElse(searchTerm, searchValue, orderBy)
select s;
return items.Take(10);
}
}
IDK你,但我認爲這是相當真棒考慮正在完成所有的工作,多數民衆贊成。
哦順便說一句,對「在哪裏(S,S)」擴展的更多信息可以在ScottGu's awesome blog
不是L2S專業版,但我希望它只能在SubmitChanges()中打開和關閉。 – mxmissile 2009-09-16 16:31:46