stored procedures

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
jbmeeh
Posts: 3
Joined: Fri 21 Nov 2008 18:47

stored procedures

Post by jbmeeh » Tue 25 Nov 2008 22:25

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?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 26 Nov 2008 07:33

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.

jbmeeh
Posts: 3
Joined: Fri 21 Nov 2008 18:47

cannot add view

Post by jbmeeh » Wed 26 Nov 2008 21:53

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 27 Nov 2008 07:29

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).

Post Reply