DBML template

The Dbml.cst template creates a LINQ to SQL dbml file. The file conforms to Microsoft's DbmlSchema.xsd schema, the same format the LINQ to SQL designer uses, so you can also edit the generated file in the designer.

If the dbml file doesn't exist, the template creates it. If it does exist, the template reads it and updates it, so you can change the file and keep your changes when you run the template again. Only some attributes are preserved, though: see Safe attributes.

Warning

The template removes tables, columns and associations that it doesn't find in the database.

Safe attributes

You can change these attributes in the dbml file, and the template keeps your changes when it updates the file. They're listed as XPath expressions.

Attribute Description
Database/@Class The name of the generated DataContext class.
Database/@EntityNamespace The namespace of the entity classes.
Database/@ContextNamespace The namespace of the DataContext class.
Table/@Member The name of the table's property in the DataContext class.
Type/@Name The name of the entity class.
Column/@Member The name of the column's property in the entity class.
Column/@Storage The private field LINQ to SQL uses to assign values.
Association/@Member The name of the association's property.
Association/@Storage The private field LINQ to SQL uses to assign the association.
Association/@DeleteOnNull Deletes the row when the association is set to null. The value isn't kept if the template's IncludeDeleteOnNull property is False.
Function/@Method The name of the method for the database procedure.
Parameter/@Parameter The method argument name that maps to the procedure parameter.

Properties

Note

The EnumList, IgnoreList and IncludeList properties take a list of regular expressions that match the full name of a table, view or command. For example, ^dbo.Account$ matches the Account table. Expresso is a useful tool for building regular expressions.

Category Property Description
1. Database CleanExpression Regular expressions that clean table, view, column and procedure names. Text that matches is removed from the name.
EnumList Regular expressions that identify enum tables.
IgnoreList Regular expressions for the tables, views and procedures to leave out of the mapping.
IncludeList Regular expressions for the tables, views and procedures to include in the mapping. When you set this property, IgnoreList is ignored and only the matching objects are used.
IncludeFunctions Includes stored procedures and user functions in the mapping.
IncludeViews Includes views in the mapping.
SourceDatabase The database to generate the dbml file for.
2. Class ContextNamespace The namespace of the DataContext class file.
DataContextName The name of the DataContext class.
EntityBase The base class of the entities.
EntityNamespace The namespace of the entity class files.
IncludeDeleteOnNull Generates the DeleteOnNull attribute for associations.
NamingConventions Options for naming objects in the dbml file: AssociationNaming adds a list suffix to associations or pluralizes them, EntityNaming names entities in singular or plural form, and TableNaming is the table naming convention your database follows.
3. Enum NameColumn Regular expressions that identify an enum table's name column.
DescriptionColumm Regular expressions that identify an enum table's description column.
4. Mapping DbmlFile The path of the dbml file to generate.
UserAssociations Associations you defined yourself, which aren't removed when the template syncs the dbml file with the database.