एक कनेक्शन तब बनाया जाता है जब आप वास्तव में गणना करना शुरू करते हैं और जब आप सबमिटChanges (यदि परिवर्तन किए जाते हैं) को दबाते हैं। मुझे यकीन नहीं है कि उपरोक्त कोड में केवल एक कनेक्शन खोला गया है और उपयोग किया गया है, लेकिन मुझे पता है कि उन दो स्थानों में मैंने बताया है, आप एक कनेक्शन का आह्वान करेंगे।
आपको LinqPad और how to use it पर dimecasts पर देखना शुरू करना होगा। इसके अलावा पर Delayed Execution features of Linq 2 Sql
नोट उनके श्रृंखला की जाँच, कुछ इस तरह (getTenSomethingElse (रों, रों, रों)) डाटाबेस क्वेरी नहीं है, कम से कम जब तक नहीं आप वापसी मान से अधिक की गणना शुरू
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);
}
}
आपके बारे में आईडीके लेकिन मुझे लगता है कि किए जा रहे सभी कार्यों पर विचार करने के लिए काफी भयानक होना चाहिए।
ओह btw, कि "कहाँ (रों, रों)" विस्तार के बारे में अधिक जानकारी के लिए एसक्यूएल पर ScottGu's awesome blog
स्रोत
2009-09-21 16:34:10
कोई एल 2 एस समर्थक नहीं है, लेकिन मुझे उम्मीद है कि यह केवल सबमिटChanges() में खुल जाएगा और बंद होगा। – mxmissile