views:

51

answers:

2

Sorry this is quite a vague question. Been trying to find information on using a View with Entity Framework 4. Want to use it as a read only view, no interested in inserting/updating/deleting... Would just like to use a POCO with a view...

[Update]

Thanks to the responders. Zeeshan, actually reading your book currently.

I can add a view via the "Update Model from Database" menu item and works great. Just need to figure out how to setup the associations now...

+1  A: 

You can add views to the Entity Designer the same way you do with tables, then treat the views as entities themselves. They're not treated exactly the same internally, and you may have to do some editing of the underlying XML.

Your question isn't clear on whether you're looking specifically for the difference between views in 3.5 and 4.0, but if you're looking for a general discussion of how views work in EF, this link has some information about it (based on 3.5):

Entity Framework: Creating a model using views instead of tables

Justin Morgan
Not precisely the same as with tables, as views have no PKs/FKs, so you have to specify the key/relationship info manually.
Craig Stuntz
Yeah, that's what I was talking about with the manual editing of the XML.
Justin Morgan
+1  A: 

Views are fully supported in RTM. One nice feature sneaked in very late in the product life cycle is, you can customize the key of the view from the conceptual model and it will sync it with the storage model as well. However there is still paint point with View where it needs to be mapped to an entity which must have a key. In future a view may be allowed to get mapped to a complex type. You can also use ExecuteStoreQuery for better performance.

zeeshanhirani
I'm not sure what you mean by the part where you say "it needs to be mapped to an entity which must have a key".
Bryce Fischer
Typically if you have a view for which you do not want to perform CRUD, it is really serving summary or reporting data. In that case a view may not have a column that can be defined as the key. However since EF requires that a view be mapped to an entity, you must configure the key for th entity through the designer which prior, you had to do by editing the xml manually. Note: An entity by its very definition means it must have a key.
zeeshanhirani