The Table attribute is required by LINQ to SQL, and maps an entity class (a class that has been designated
as an entity) to a table or view. The Table attribute also has a single property, Name, which specifies the
name of the relational table or view.
The following is an example of the Table attribute being applied to a class to define a mapping between
the HumanResources.Employee table and the Employee class, and mapping a class named Contact with
the Person.Contact table in the Adventureworks database:
[Table(Name = "HumanResources.Employee")]
public class Employee
{
//
}
[Table(Name = "Person.Contact")]
public class Contact
{
//
}
Remember, only those entity classes that have been mapped to a table can be saved to the database. That
means that if you map the Person.Contact table to an entity class but don??™t map the
HumanResources.Employee table to an entity class, you can only work with the Person.Contact
table (query data, save, and so on).
Keep in mind that classes marked with the [Table] attribute are treated as persistent classes by LINQ
to SQL.
Pages:
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336