Generate Classes based on XML Doc?
Thanks in advance!
Thanks in advance!
SqlMetal can already generate entity classes based on an XML based mapping file (dbml). From the LINQ to SQL Whitepaper,
"To instruct SQLMetal to generate a DBML file use the tool as follows:
SqlMetal /server:.\SQLExpress /database:Northwind /pluralize /xml:Northwind.dbml
Once the dbml file is generated, you can go ahead and annotate it with class and property attribute to describe how tables and columns map to classes and properties. Once you have finished annotating the dbml file, you can generate your object model by running the following command:
C#
SqlMetal /namespace:nwind /code:Northwind.cs Northwind.dbml"Using this methodology, you can customize the data mappings in the dbml file and generate the classes dynamically as necessary. Naturally, you do not have the flexibility that some code generation systems offer because you can't fully customize the generated code as you may be able to do with CodeSmith or other code gen systems.
The code generation tool built into SqlMetal is designed to generate the code we *think* you'll want. However, using SqlMetal to generate code is not required to use LINQ to SQL. You could write the classes by hand, being an minimal as you want, or use another code generation tool like Miha has done. This was the purpose of the DBML file. It offers a common 'model' of the domain objects and data context and allows for potentially mutliple designers and multiple code generators. Howeve, there currently is no way to plug-in a different code generator directly when using the LINQ to SQL designer. You'll have to resort to a second manual step after using the designer to call out to a different code generator.
Thanks again!
I think the guys above misinterpreted your question. What you are looking for is probably
Linq To XML. Haven't used it myself, but I guess you can generate some kind of object model
for XML file contents similar to what linq to sql does for a database table.
kind regards,
Patrick De Block