Search code examples
c#linq-to-sqlsqlmetal

LINQtoSQL: What is the Map File for?


I am currently using SqlMetal to generate my dbml and code file. I am using Visual Studio 2010 and SqlServer 2000. Unfortunately Visual Studio 2010 only support SqlServer 2005 or greater so I am unable to generate the code using the built-in wizard.

I have been generating my dbml and code files by using:

>sqlmetal /server:myServer /database:myDatabase /dbml:myDatabase.dbml
>sqlmetal /code:myDatabase.cs myDatabase.dbml

I have noticed there is a map file option.

Generates an XML mapping file instead of attributes. Cannot be used with /dbml option.

MSDN on SqlMetal.exe

I was wondering if I should also be using a map file? What is the advantages to a map file over code attributes?


Solution

  • See: http://msdn.microsoft.com/en-us/library/bb386907.aspx (mapping) See: http://msdn.microsoft.com/en-us/library/bb386971.aspx (attributes)

    Bascially you can use an external mapping file (POX) instead of the dbml which is supposed to keep the mapping code separate from your application code.

    I would use the DBML unless you plan on needing to be able to change mapping without recompilation or you need to have exact control over the mapping (maybe for odd custom stuff). Map file won't change. dbml might (removing any custom changes you may have made).