New Posts New Posts RSS Feed: Save ALL Data to Local Storage?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Save ALL Data to Local Storage?

 Post Reply Post Reply
Author
HFloyd View Drop Down
Groupie
Groupie


Joined: 27-Jul-2007
Location: United States
Posts: 44
Post Options Post Options   Quote HFloyd Quote  Post ReplyReply Direct Link To This Post Topic: Save ALL Data to Local Storage?
    Posted: 03-Nov-2008 at 2:37pm
Hi,

I would like an easy way to save all the data for all the entities in one operation. I have looked at the "Disconnected" Tutorial and Level 100 code examples. These examples are based on a simple data graph and the data for the related entities is all pulled together using SPAN queries.

What I am interested in in basically pulling down all the entities regardless of their individual relations to one another. I would like this to be a centralized operation, not running necessarily from a single entity form. I assume this is all do-able and have looked at a possible way to accomplish it.

What I have mocked up is this:

public static void GetAllData ()
        {
            EntityList<ContactMethod> mELContactMethod = new EntityList<ContactMethod>();
            mELContactMethod = MainPm.Manager.GetEntities<ContactMethod>();

            EntityList<ContactMethodType> mELContactMethodType = new EntityList<ContactMethodType>();
            mELContactMethodType = MainPm.Manager.GetEntities<ContactMethodType>();

            EntityList<HBType> mELHBType = new EntityList<HBType>();
            mELHBType = MainPm.Manager.GetEntities<HBType>();

            EntityList<HouseholdBusiness> mELHouseholdBusiness = new EntityList<HouseholdBusiness>();
            mELHouseholdBusiness = MainPm.Manager.GetEntities<HouseholdBusiness>();

            EntityList<Person> mELPerson = new EntityList<Person>();
            mELPerson = MainPm.Manager.GetEntities<Person>();

...<And so on, one for each entity in the system>...

        }


Which I would call right before the "... mPersMgr.SaveEntitySet(path); ..." type code.

Does this seem reasonable? Or do I need to somehow get everything into a single entity graph (like an uber-entity, which linked all the entities together using SPANs)?

Thanks for any thoughts on this.

Heather

Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2008 at 7:15pm
It should work as you have it, but there is no need to load the entities into lists.  You should be able to simply do this:


public static void GetAllData () {
    pm.GetEntities<ContactMethod>();           
   
pm.GetEntities<ContactMethodType>();
    pm.GetEntities<HBType>();
    pm.GetEntities<HouseholdBusiness>();
    pm.GetEntities<Person>();
}



Of course, it may be more flexible to generate an array of types and do something like this:


public static void GetAllData(IEnumerable<Type> entityTypes) {
    foreach(Type type in entityTypes) {
        pm.GetEntities(type);                   
    }
}


This better follows the open-closed principle so that you can change which types you load without modifying the method directly.
Back to Top
HFloyd View Drop Down
Groupie
Groupie


Joined: 27-Jul-2007
Location: United States
Posts: 44
Post Options Post Options   Quote HFloyd Quote  Post ReplyReply Direct Link To This Post Posted: 06-Nov-2008 at 3:06pm
Pardon my ignorance, but how would I create the "entityTypes" array to pass in?
(I'm new to interfaces, etc)

What I would then like to do is something like this:


IEnumerable<Type> TypeList;

foreach (Type t in ~all the objects in my business model~)
{
    TypeList.Add(t);
}


I know the syntax is way off for this, but perhaps you understand what I am getting at?

I noticed that the EntityClass object represents all the different objects in my model:

        EntityList<EntityClass> melEC = new EntityList<EntityClass>();
            melEC = MainPm.Manager.GetEntities<EntityClass>();
           
            foreach (EntityClass ec in melEC  )
            {
                ~do something with the ec~
            }


I tried this:

            foreach (EntityClass ec in melEC)
            {
                MainPm.Manager.GetEntities(ec.GetType());
            }


but ec.GetType() always returns <EntityClass>, of course...

Any ideas?

Thanks, Heather



Edited by HFloyd - 06-Nov-2008 at 3:55pm
Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2008 at 11:40am
Well, I don't know if it would be such a good idea because this would pull down all of your data from your database in one fell swoop.  Probably not very scalable.  You could use reflection to find all entity types in your model by retrieving types that are sealed and that inherit from Entity.  Alternatively you could just make a list of types you want to preload, which would be more strategic than just loading all data.

Example:


public IEnumerable<Type> PreloadEntityTypes() {
    var typeList = new List<Type>();
    typeList.Add(typeof(ContactMethod));
    typeList.Add(typeof(ContactMethodType));
    /* etc */
    return typeList;
}

Back to Top
HFloyd View Drop Down
Groupie
Groupie


Joined: 27-Jul-2007
Location: United States
Posts: 44
Post Options Post Options   Quote HFloyd Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2008 at 4:53pm
Thanks, Jeff,

That worked well!

Have a great weekend!

Heather

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down