Loading Static Data from Database in an RIA Application

153 views Asked by At

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!

1

There are 1 answers

0
InnerException On

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