New Posts New Posts RSS Feed: Unable to cast EntityManager as custom type on the server
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Unable to cast EntityManager as custom type on the server

 Post Reply Post Reply
Author
akukucka View Drop Down
Newbie
Newbie
Avatar

Joined: 22-Jul-2010
Location: Rochester, NY
Posts: 11
Post Options Post Options   Quote akukucka Quote  Post ReplyReply Direct Link To This Post Topic: Unable to cast EntityManager as custom type on the server
    Posted: 11-Aug-2010 at 8:05am
The EntityManager that we use is actually something we code-gen ourselves; it derives from an object that derives from IdeaBlade.EntityModel.EntityManager.

When doing something like verification of a property, we want to go to the database to make sure the input is valid.  We do this by casting the EntityManager on the entity to our own type and then querying the EntityQueries contained within.  This works great on the client with a property trigger, but with instance verification on the server we get an InvalidCastException when trying to cast EntityManager to our derived type:

Unable to cast object of type 'IdeaBlade.EntityModel.EntityManager' to type 'MaintenanceProject.Business.EntityManager'.

I'm not sure if the EntityManager is replaced on the server or our custom EntityManager type isn't making it to the server... any ideas?

Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 16-Aug-2010 at 5:17pm
The client-side EntityManager is a subtype of EntityManager that adds a bit of syntactic sugar to EntityManager. (For example, it lets you say 
em.Customers
to get the query for Customers, whereas with EntityManager property you have to say
em.GetQuery<Customer>()
).

You can't cast the client-side EntityManager to your subtyped one, but you can still perform all of the core functions of the EntityManager (querying, verification, saving, etc.) by using the methods and properties it provides.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down