This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm trying to get a single table inheritence scenario set using stored procedures. I'm running into a problem where I do a .Find<Employee>() where Employee is a subclass of a User entity. It executes the select all procedure and the throws an exception (below) because it is trying to return ALL entities and not just those by the type I am requesting.In my model, I tried not defining the stored procedure definitions at the subclass level, but that failed horribly so I added them to the subclasses and select by id, update, etc seem work. Just not the Find, although I need that working to verify.
Thoughts?
The value "Manager[Id=32, EntityState=Default]" is not of type "Supply.Model.Employee" and cannot be used in this generic collection.Parameter name: value etc. |
|
|
We can't add filtering criteria to a stored procedure. Therefore when you call Find<T>(ProcedureQuery), we get the results of the procedure, materialise them, and try to load them into the resulting IList<T> collection. We can't add the "where discriminator == value" clause that we would do on a table query. In this case, your procedure is returning non-Employee rows as well as Employee rows, so we fail when we try to load the non-Employee objects into the IList<Employee>. You should instead either update your stored procedure to return only rows that map to Employee objects, or write your query to respect the type of objects (User) returned by the stored proc and perform additional client-side filtering to extract only the Employees. The latter is easy to do using the OfType operator: var employees = unitOfWork.Find<User>(procedureQuery).OfType<Employee>().ToList(); |
|