New Posts New Posts RSS Feed: Getting a DefaultManager (Sort of)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Getting a DefaultManager (Sort of)

 Post Reply Post Reply
Author
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Topic: Getting a DefaultManager (Sort of)
    Posted: 23-Jun-2009 at 10:39am
We were receiving the following errors, depending on how we got into the code:
1) Error loading entity relations
2) Type conflict: the DefaultManager is currently of type EntityManager
3) Type Deal must inherit from Entity does not

In our Deal class, I had implemented a static Create method:

public static Deal Create(User user)
{
    Deal deal = _manager.CreateEntity<Deal>();
    GetATemporaryKey(deal);
    InitializeDefaults(deal, user);
    AddToManager(deal);
    InitializeChildren(deal, user);
    return deal;
}

which used a static private EntityManager which was declared like this:

static DomainModelEntityManager _manager = DomainModelEntityManager.DefaultManager;

It turns out that at run time, this is actually initialized to an EntityManager, NOT a DomainModelEntityManager as I had expected.

I created a new LocalEntityManager class like this:

public static class LocalEntityManager
{
    private static DomainModelEntityManager _em;

    public static DomainModelEntityManager DefaultManager
    {
        get
        {
            if (_em == null)
               _em = new DomainModelEntityManager();
            return _em;
        }
    }
}

and changed the declaration in Deal like this:

static DomainModelEntityManager _manager = LocalEntityManager.DefaultManager;

Now, it all works like a charm.
[It only took 2 days to find this...]
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down