Page 1 of 1
stored procedures
Posted: Tue 25 Nov 2008 22:25
by jbmeeh
If I have a stored procedure returning a subset of the fields in a table, how do I map it to an entity? If I try to map to an entity with all the fields, then the execution of the stored procedure fails with a message indicating that the datareader is incompatible with the entity. If I define a new entity containing just the fields in the stored procedure, then it requires a mapping to a table. If I do that, then it complains that the two entities can be in conflict.
Since stored procedures returning cursors will not always map directly to tables, then how should this be handled?
Posted: Wed 26 Nov 2008 07:33
by AndreyR
The best way is to create a view in your DB with the proper subset of columns and after that map the
result set of a stored procedure to the collection of entities that corresponds to that view.
cannot add view
Posted: Wed 26 Nov 2008 21:53
by jbmeeh
The entity model tool appears to be very fragile. I have defined a new view in the database. When I try to add it to the enity model, the new view appears in the selection list but it cannot be added to the entity model with no errors reported. Also, if I have previously added stored procedures to the entity model, then they no longer appear after I try to add the new view.
Posted: Thu 27 Nov 2008 07:29
by AndreyR
The view cannot be added without warnings because it has no primary key defined.
The entity key for a view is generated from the columns with NOT NULL constraint.
Also, we don't recommend to use the Update model from Database wizard of EDM Designer.
Instead we recommend to regenerate the model from scratch (this is an issue of Microsoft EDM Designer, mainly).