Search code examples
linqcode-generationobject-modelsqlmetal

How to read a DBML file and map it into an object model in .NET?


I'm planning to write a code generator to generate UI (forms, grids, etc.). Since I'm using LINQ I'm planning to read a DBML file for metadata extraction purposes. Is there some API to read the DBML object model (database, tables, columns, and associations)?

I've opened SQLMetal.exe with Red Gate Software's .NET Reflector. It contains a namespace called LinqToSqlShared.DbmlObjectModel and it seems it contains everything I need to read a DBML object model. The bad news is: that namespace is not exposed for external consumption and all classes are declared as "Friend" (or sealed).

Once again, does something exist, like the LinqToSqlShared.DbmlObjectModel namespace, to read DBML to an object model in .NET.? Or do I have to write it my self?


Solution

  • Have a look at how the model is read in L2ST4 project. You could reuse the T4 file.