Print Page | Close Window

Unable to cast EntityManager as custom type on the server

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2060
Printed Date: 21-Apr-2026 at 11:51pm


Topic: Unable to cast EntityManager as custom type on the server
Posted By: akukucka
Subject: Unable to cast EntityManager as custom type on the server
Date 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?




Replies:
Posted By: GregD
Date 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.



Print Page | Close Window