views:

195

answers:

4

Hi,

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?

A: 

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)

kubal5003
A: 

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

nportelli
A: 

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...

KristoferA - Huagati.com
I noticed this but I only want to serialize specific columns/tables so don't want to do it datacontext wide. Anyway to do this?
Fermin
No, then you need to switch out the code generator as others have mentioned. Take a look at Damien Guard's T4 templates: http://l2st4.codeplex.com/
KristoferA - Huagati.com
A: 

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.

Devart