Database Views

When I generate the entity classes for the Northwind database in Chapter 12, I specify the /views option to have entity class mappings for database views created, but I have yet to mention views and how to query them. The entity class generation tools, SQLMetal and the Object Relational Designer, declare a Table<T> property in the [Your]DataContext class for each database view and create a corresponding entity class T. You query them just like tables. In general, they behave just like tables except for the fact that they are read-only.

Because the entity classes generated for views do not contain entity class properties that are mapped as primary keys, they are read-only. If you consider that without primary keys, the DataContext ...

Get Pro LINQ: Language Integrated Query in C# 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.