SqlMetal for Linq

SqlMetal builds a data access layer in seconds. The output is not just a first generation data access; SqlMetal’s output includes all defined relationships (based foreign keys) between your tables. SqlMetal will produce a class for each table and, optionally, classes for all views, stored procedures and user-defined functions.

SqlMetal can generate strongly typed interfaces for stored procedures and user-defined functions. From the developer point of view, it is now a complete breeze to call either a stored proc and/or a user-defined function.

SqlMetal can generate a DataContext for your entire database with a single command.

This is very useful if you have a large number of tables in your system, as dragging and dropping them onto the designer would have got boring very quickly. You can find SqlMetal at [C:]Program FilesMicrosoft SDKsWindowsv6.0Abin.

Lets create Northwind datacontext:

C:Program FilesMicrosoft SDKsWindowsv6.0Abin>sqlmetal /server:.sqlexpress
/database:northwind  /code:”c:tempnorthwind.cs”

We can then include the class within our project and use it as if the designer had created it. We can also get SqlMetal to include all of our views, functions and stored procedures. (use /sprocs /views /functions to extract these objects).

SQLMetal can also output the dbml (/dbml:file.dbml) or mapping (/map:file.xml) file for the database.

C:Program FilesMicrosoft SDKsWindowsv6.0Abin>sqlmetal /server:.sqlexpress
/database:northwind /dbml:”c:tempnorthwind.dbml”

SqlMetal has also generated an external XML Mapping File that maps the classes generated to the database tables, which is much more complete than what I had done my self…

C:Program FilesMicrosoft SDKsWindowsv6.0Abin>sqlmetal /server:.sqlexpress
/database:northwind /map:”c:tempnorthwind.map”


The SqlMetal tool is useful to generate C# or VB.NET objects mapped on SQL Server database. It provides classes with members and properties mapped on table and view columns. It reflects the relationships between tables. It provides also a class derived from base class DataContext which maps, on request, functions and stored procedures, making difference between table functions and scalar functions and between stored procedures which returns a rowset and those who perform only operations such as insert, update and delete.

From my point of view: great and useful tool.


Technorati Tags:


del.icio.us Tags:
%d bloggers like this: