Generation custom files from dbml file?

669 Views Asked by At

I've been having a look at making changes to the partial classes generated from a DBML file. I was reading into using the sqlmetal.exe tool but it appears that you can't do much customisation of what it actually spits out.

I'm wanting to make changes to the file for serialization purposes, I'd like to add the Data Member Attribute to specified properties in the generated partial classes.

Is this possible to do using the sqlmetal.exe tool or would I need to write my own tool for the file generation?

4

There are 4 best solutions below

0
On BEST ANSWER

You could check out T4 templates or CodeSmith for file generation.

0
On

No it is not. You can accomplish this with Entity Framework.

http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx

Code written by Jaroslaw Kowalski works much the same way that Linq to SQL does.

It has some issues, but you can do everything with it, because you have the source. I'm going to publish my version soon(support for stored procedures, improved databinding experience and many other useful features)

2
On

If you want the datacontract and datamember attributes to be added, simply change the "Serialization Mode" property in the L2S designer's datacontext properties from "None" to "Unidirectional". All entity classes will then be datacontracts, and their members will be datamembers...

0
On

The upcoming Beta version of Entity Developer will contain highly customizable T4-like templates for code generation.
Also we have added functionality to divide the generated code into separate files.