New Posts New Posts RSS Feed: Two Entities and Two DataBase problem
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Two Entities and Two DataBase problem

 Post Reply Post Reply
Author
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Topic: Two Entities and Two DataBase problem
    Posted: 03-Feb-2011 at 11:52am
Hi Molinari;

Please see code example below.

[TestMethod]
    public void UsingDefaultManager() {      
      var mgr1 = new NorthwindIBEntityManager();
      var mgr2 = new FantasyFootballEntityManager();

      var a = mgr1.Employees.FirstOrNullEntity();
      var b = mgr2.Clubs.Take(9).ToList();

      var default1 = NorthwindIBEntityManager.DefaultManager;
      EntityManager.DefaultManager = mgr2;
      var default2 = FantasyFootballEntityManager.DefaultManager;
      var clubInCache = default2.FindEntities<Club>(EntityState.AllButDetached).ToList();
    }

The last query finds all entities of type Club in cache. The results are 9 clubs which is correct because the previous query

mgr2.Clubs.Take(9).ToList();

takes 9 Club entities and put them in cache.
Back to Top
Molinari View Drop Down
Groupie
Groupie
Avatar

Joined: 25-Aug-2010
Posts: 42
Post Options Post Options   Quote Molinari Quote  Post ReplyReply Direct Link To This Post Posted: 03-Feb-2011 at 11:40am
Hi Denisk,

Ok.. but I need using two database..and project has only one EntityManager so when i need to run the query EntitiesFirst() I set in EntityManager after I need execute the query EntitiesSecond() then set new again...

I create one Test .... every time change EntityManader.DefaultManager.... cache is Empty...

if you can post the code...for example..I thank
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 03-Feb-2011 at 11:11am
Hi Molinari;

No, you don't need to set it to new EntitiesSecond() every time. You can set it to any existing EntityManager of type EntitiesSecond and use its cache.
Back to Top
Molinari View Drop Down
Groupie
Groupie
Avatar

Joined: 25-Aug-2010
Posts: 42
Post Options Post Options   Quote Molinari Quote  Post ReplyReply Direct Link To This Post Posted: 03-Feb-2011 at 4:28am
Hi Denisk,

Then mean that I can never use the cache on EntitiesSecond. because I need set   NEW EntityManager.DefaultManager = new EntitiesSecond();
every time before executing a query ? Or has some way to use this cache?

thanks..
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 02-Feb-2011 at 3:31pm
Hi Mollinary;

The DefaultManager is a static shared property across all EntityManager(s). This means that the following are the same instance.

EntityManager.DefaultManager
EntitiesFirst.DefaultManager
EntitiesSecond.DefaultManager

Which means that before you get the DefaultManager and assign it to a different type, you need to set it to the proper type first as follows:

EntityManager.DefaultManager = new EntitiesSecond();
EntitiesSecond _em2 = EntitiesSecond.DefaultManager;

Hope this helps.
Back to Top
Molinari View Drop Down
Groupie
Groupie
Avatar

Joined: 25-Aug-2010
Posts: 42
Post Options Post Options   Quote Molinari Quote  Post ReplyReply Direct Link To This Post Posted: 02-Feb-2011 at 7:38am
I have two entities and two database... Consequently.. two EM..

EntitiesFirst _em = new EntitiesFirst();
_em.DefaultQueryStrategy = QueryStrategy.DataSourceOnly;

EntitiesSecond _em2 = new EntitiesSecond();
_em2.DefaultQueryStrategy = QueryStrategy.Normal;



When I use EntitiesFirst.. sucess but when i use EntitiesSecond..

public static void Test()
{
   EntitiesSecond _em2 = EntitiesSecond.DefaultManager;

_em2.Employer.Where(c=>c.id == 1)....
}

Show Error...
Type conflict: the DefaultManager is currently of type EntitiesFirst

how to use it properly.

Thanks


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down