在 RIA 应用程序中从数据库加载静态数据

发布于 2024-12-11 06:24:47 字数 1425 浏览 3 评论 0原文

作为我正在创建的 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 技术交流群。

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

发布评论

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

评论(1

若水微香 2024-12-18 06:24:47

我不会在这里打扰 DomainDataSource,只需在 App.cs 中有一个静态 myDomainContext 即可 ping:

 LoadOperation<my_entity> loadComplete = App.myDAL.Load(App.myDAL.Getmy_entityQuery());

然后,如果您想知道它何时完成获取:

loadComplete.Completed += new EventHandler(loadChain_Completed);

void loadChain_Completed(object sender, EventArgs e)
{
     //Stuff to do when data has been fetched, for example
     return App.myDAL.my_entitys.ToList();
}

I wouldn't bother with a DomainDataSource here, just have a static myDomainContext in App.cs that you can ping:

 LoadOperation<my_entity> loadComplete = App.myDAL.Load(App.myDAL.Getmy_entityQuery());

And then if you care about knowing when it's done fetching:

loadComplete.Completed += new EventHandler(loadChain_Completed);

void loadChain_Completed(object sender, EventArgs e)
{
     //Stuff to do when data has been fetched, for example
     return App.myDAL.my_entitys.ToList();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文