Subsonic 3 使用内存的方式

发布于 2024-10-28 03:37:03 字数 359 浏览 5 评论 0原文

我尝试对 Subsonic 3、数据集和实体框架进行比较。原因是为了我的实习,我必须明确我的选择。到目前为止,我还知道数据集按以下方式检索数据:

  1. 数据库到内存
  2. 查询实体框架(.NET 版本 3.5)的内存中数据库
  3. 结果的

查询按以下方式执行。 (使用.net 3.5,因为它需要在SharePoint 2010上工作,而由于CLR版本,这个仅支持.net 3.5)对

  1. 数据库结果进行查询
  2. 返回到内存中对象的
  3. 返回结果

到目前为止,我还没有找到Subsonic 3的方案他们是如何做到的。 我希望你们中的一个人能帮助我

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧竹 2024-11-04 03:37:03

这完全取决于您使用的策略(ActiveRecord / LinqTemplates / SimpleRepository)

  • ActiveRecord:
    每个记录都将其自己的实例保存到存储库中,这将导致大型列表占用大量内存。

  • Linq 模板:
    内存使用量少得多,您拥有一个数据库实例,其中保存每个表的方案和纯数据。

  • 简单存储库
    更不用说,因为存储库实例对您的数据库一无所知。它几乎只使用内存中的纯数据。

我建议同时使用 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),它有一个运行良好的 ServerMode使用 SubSonic 的 LinqTemplates(因为它可以绑定到 IQuerable,并且它本身处理 IQuerable 上的分页/排序/过滤,并且一次只需要几条记录。
这大大减少了我们应用程序的内存占用和加载性能(将一堆记录加载到数据表中)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文