在 RIA 应用程序中从数据库加载静态数据
作为我正在创建的 WCF RIA 应用程序的一部分,我想在本地缓存一堆静态支持数据(供水系统、国家、省份的列表;诸如此类的事情)。我创建了一个简单的静态类来将列表缓存到 (LocalStateContainer.cs)。
示例:
public static class LocalStateContainer
{
private static IEnumerable _waterSystems;
public static IEnumerable WaterSystems
{
get
{
if (_waterSystems== null)
{
DomainDataSource ds = new DomainDataSource();
Web.SuperDomainContext d = new Web.SuperDomainContext();
ds.DomainContext = d;
ds.QueryName = "GetWaterSystems";
ds.Load();
_waterSystems = ds.Data;
}
return _waterSystems;
}
}
}
以这种方式使用 DomainDataSource 是否谨慎?我是否可以不那么容易去:
public static class LocalStateContainer
{
private static IEnumerable _waterSystems;
public static IEnumerable WaterSystems
{
get
{
if (_waterSystems== null)
{
Web.SuperDomainContext d = new Web.SuperDomainContext();
_waterSystems = from w in d.WaterSystems select w;
}
return _waterSystems;
}
}
}
更广泛地说,什么时候使用 DomainDataSource 检索数据与直接访问 DomainContext 比较明智?我想对于双向链接 DomainDataSource 是可行的方法,但是直接从 DomainContext 中提取静态数据是否有害/愚蠢?
任何见解都会受到赞赏;我对 Silverlight 还很陌生,所以很抱歉,如果这是米老鼠的东西。
谢谢!
As part of a WCF RIA application I'm creating, I'd like to cache a bunch of static supporting data locally (lists of water systems, countries, provinces; that sort of thing.) I've created a simple static class to cache the lists into (LocalStateContainer.cs).
Example:
public static class LocalStateContainer
{
private static IEnumerable _waterSystems;
public static IEnumerable WaterSystems
{
get
{
if (_waterSystems== null)
{
DomainDataSource ds = new DomainDataSource();
Web.SuperDomainContext d = new Web.SuperDomainContext();
ds.DomainContext = d;
ds.QueryName = "GetWaterSystems";
ds.Load();
_waterSystems = ds.Data;
}
return _waterSystems;
}
}
}
Is it prudent to use a DomainDataSource in this way? Could I not just as easily go:
public static class LocalStateContainer
{
private static IEnumerable _waterSystems;
public static IEnumerable WaterSystems
{
get
{
if (_waterSystems== null)
{
Web.SuperDomainContext d = new Web.SuperDomainContext();
_waterSystems = from w in d.WaterSystems select w;
}
return _waterSystems;
}
}
}
More broadly, when is it smart to use a DomainDataSource to retrieve data versus accessing the DomainContext directly? I imagine for 2-way linking the DomainDataSource is the way to go, but is it harmful/foolish to yank static data directly out of the DomainContext?
Any insight is appreciated; I'm still very new to Silverlight so apologies if this is mickey mouse stuff.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会在这里打扰 DomainDataSource,只需在 App.cs 中有一个静态 myDomainContext 即可 ping:
然后,如果您想知道它何时完成获取:
loadComplete.Completed += new EventHandler(loadChain_Completed);
I wouldn't bother with a DomainDataSource here, just have a static myDomainContext in App.cs that you can ping:
And then if you care about knowing when it's done fetching:
loadComplete.Completed += new EventHandler(loadChain_Completed);