Print Page | Close Window

Getting a DefaultManager (Sort of)

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1342
Printed Date: 22-Sep-2025 at 6:08am


Topic: Getting a DefaultManager (Sort of)
Posted By: skingaby
Subject: Getting a DefaultManager (Sort of)
Date 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...]



Print Page | Close Window