Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Represent Columns as Class Members (LINQ to SQL)

Use the LINQ to SQL ColumnAttribute attribute to associate a field or property with a database column.

To map a field or property to a database column

The following code maps the CustomerID field in the Customer class to the CustomerID column in the Customers database table.

[Table(Name="Customers")]
public class customer
{
    [Column(Name="CustomerID")]
    public string CustomerID;
    // ...
}

You do not have to specify the Name property if the name can be inferred. If you do not specify a name, the name is presumed to be the same name as that of the property or field.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.