企业库 5.0 是否缓存数据读取器和访问器方法的自定义类之间的映射
想知道 Enterprise Library 5.0 的 Accessor 方法是否缓存 datareader 的字段以及自定义类以提高性能,以便它不会使用反射在自定义类上查找字段名称,并且在将 datareader 映射到时不会在 datareader 上查找字段名称物体?因为将每个访问/代码块的自定义类字段映射到数据读取器字段是一项相当昂贵的操作
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
var r = db.ExecuteSqlStringAccessor<Region>("SELECT * FROM Region");
}
}
public class Region
{
public string RegionnId { get; set; }
public string Name { get; set; }
}
Wanted to know if the Accessor methods of Enterprise Library 5.0 cache the fields of datareader as well as custom classes for performance such that it does not look up field names on custom classes using reflections and does not look up field names on datareader when mapping datareader to objects? Because its a pretty expensive operation to map custom class fields to datareader fields for every access / code block
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
var r = db.ExecuteSqlStringAccessor<Region>("SELECT * FROM Region");
}
}
public class Region
{
public string RegionnId { get; set; }
public string Name { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从代码来看,该方法经过:
then 到
which经过
which是:
所以不;我没有看到任何缓存的证据。您可以添加一些,或者您可以使用已经实现物化器和参数化缓存的 domething (*咳嗽* dapper-dot-net *咳嗽*)
From the code, that method goes via:
then to
which goes via
which is:
so no; I see no evidence of any caching there. You could add some, or you could use domething that already does materializer and parameterization caching (*cough* dapper-dot-net *cough*)
这是 entlib 支持团队建议的一个简单而不错的技巧(您可以在 http://entlib 查看完整线程.codeplex.com/discussions/281833):
例如:
再次从 EntLib 更新(更好的解决方案):
Here is an easy and nice hack suggested by entlib support team (you can check the full thread at http://entlib.codeplex.com/discussions/281833):
E.g.:
UPDATE From EntLib again (an even better solution):