這完全取決於你所使用(ActiveRecord的/ LinqTemplates/SimpleRepository)
ActiveRecord的策略: 每一個記錄擁有它自己的實例來回購,這將導致大型列表的高內存使用率。
LinqTemplates: 更少的內存使用情況,您有一個db的實例,它包含每個表的方案和純數據。
SimpleRepository 更少,因爲回購實例不知道任何關於您的數據庫。它幾乎只是在內存中使用純數據。
我會建議同時使用ActiveRecord和Linq模板。 Linq用於查詢大型列表,ActiveRecord用於編輯單個記錄或小型列表(< 100個條目)。
SubSonic不會按設計進行緩存,所以我不擔心這一點。 但是關於Linq的東西(所有三種策略)的好處是,只有當你需要數據時纔打到數據庫,所以你可以控制你使用多少內存。
例子:
var db = new NorthwindDb();
// does not hit the database (just an expression)
// since we only need ProductId and ProductName in this example,
// there is no need to pull the entiry Product from the database.
var query = from p in db.Products
where p.CategoryId == 5
select new {p.ProductId, p.ProductName };
// executes: SELECT COUNT(*) FROM products WHERE categoryid = 5;
var count = query.Count();
// does not execute anything
var top10 = query.Take(10);
// executes: SELECT productid, productname
// FROM products WHERE categoryid = 5 LIMIT 10
// LIMIT = MySQL paging, don't know how to write that for SQLServer
// p in this example is not a product, but an anonymous type with
// only two properties (ProductName and ProductId)
foreach (var p in top10);
Console.WriteLine("ProductId {0} Name {1}", p.ProductId, p.ProductName);
更新: 我不知道你在開發什麼樣的應用,但如果你需要在DataGrid中顯示的數據我會建議使用的DevExpress XtraGrid中(可用於WinForms,WPF/Silverlight和ASP.net),它具有與SubSonic的LinqTemplates相當好的ServerMode(因爲它可以綁定到IQuerable並且它自己處理IQuerable上的分頁/排序/過濾,並且只需要幾條記錄一次。 這大大減少了記憶力rint和加載我們的應用程序的性能(它將一堆記錄加載到數據表中)。
謝謝你的回答。現在我也可以更好地瞭解Subsonic如何工作。我嘗試使用ActiveRecords方法,但與EF相比,這非常緩慢,讀取像2000條記錄,並將1000到5000條記錄寫入數據庫。這將幫助我更好地理解Subsonic。 – 2011-03-30 07:38:36
關於亞音速的偉大之處在於,它非常接近數據庫。它的內部始終是:「創建連接,執行命令,從DataReader讀取結果」。如果你注意到某些東西很慢,那麼它可能是數據庫中可以改進的東西,或者你正在使用亞音速提供的錯誤方法(不需要從數據庫中提取產品來更新它的類別:db.Update() .Set(x => x.CategoryId = 5).Where(x => x.ProductId == 123).Execute();')。你甚至可以使用subsonic自己的查詢工具或普通的sql來查詢無法用linq投影的查詢。 –
2011-03-30 07:52:41
的更新: 該應用程序將是一個註冊系統,用於在SharePoint Intranet中工作的工作時間 – 2011-03-30 08:37:24