Question

I'am try to make a comparison between Subsonic 3, Datasets and Entity Framework.The reason why is that for my internship i have to make clear my choices. Until now i know yet that Datasets works the following way with retrieving data:

  1. DB into memory
  2. query on DB in memory
  3. result from query

Entity Framework (.NET version 3.5) does it the following way. (using .net 3.5 because it needs to work on SharePoint 2010 and this one only supports .net 3.5 because of the CLR version)

  1. query on DB
  2. result returned into objects in memory
  3. result returned

Until now i haven't found a scheme for Subsonic 3 how they do it. i hope one of you can help me

Was it helpful?

Solution

It totally depends on the strategy you are using (ActiveRecord / LinqTemplates / SimpleRepository)

  • ActiveRecord: Every single Record holds it's own instance to a repo, which will result in high memory usage for large lists.

  • LinqTemplates: Much less memory usage, you have an instance of your db which holds the scheme of every table and the pure data.

  • SimpleRepository Even less, since the repo instance does not know anything about your database. It almost only the usage of the pure data in memory.

I would suggest using both, ActiveRecord and Linq Templates. Linq for querying large lists, and ActiveRecord for editing single records or small lists (<100 entries).

SubSonic doesn't do caching by design, so I wouldn't worry about that. But the great thing about the Linq stuff (for all three strategies) is that you don't hit the database until you need the data, so you can control how much memory you use.

Example:

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);

Update: I don't know what kind of application you are developing but if you need to display data in a DataGrid I would suggest using the devexpress XtraGrid (available for WinForms, WPF/Silverlight and ASP.net) which has a ServerMode which works pretty well with SubSonic's LinqTemplates (since it can be bound to an IQuerable and itself handles the paging/sorting/filtering on the IQuerable and only needs a few records at a time. That greatly reduced the memory footprint and loading performance of our app (which loaded a bunch of records into a datatable).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top