Mapping Modifications

Modifications can be applied to your mapping which allow you to change the shape of your mapping before FluentLinqToSql generates the mapping document. These are similar to
Conventions in Fluent NHibernate.

Out of the box, Fluent Linq to Sql comes with three modifications:
  • ChangeUpdateCheckToNever - sets the UpdateCheck property for all columns to "Never"
  • UseFieldForAssociationStorage - allows Linq to Sql to use fields for assocations, bypassing public getters/setters
  • ReplacePascalCaseWithUnderscore - maps PascalCased properties to UnderscoreSeparated database fields (eg CustomerId would become CustomerId)

Modifications are added by calling the AddModification method on FluentMappingSource:

var mappings = new FluentMappingSource("MyDb");
mappings.AddModification(new UseFieldForAssociationStorage());

You can add your own conventions to your mappings by inheriting from MappingModification and overriding the appropriate methods. For example, if you wanted to prefix all table names with "tbl_" then you could write a modification like this:

public class TblPrefixModification  : MappingModification {
	protected override void HandleMapping(IMapping mapping) {
		string name = mapping.CustomProperties["TableName"].ToString();
		name = "tbl_" + name;
		mapping.CustomProperties["TableName"] = name;

Last edited Sep 6, 2009 at 2:11 PM by JeremyS, version 1


No comments yet.