The first thing to note is the syntax of the XML mapping file. You can take a look at LINQ Preview\Docs\DLINQ Mapping Schema.xsd for more information on the mapping format, but here is a shortened extract from LINQ Preview\Data\samplemapping.xml to give you a look at a concrete implementation:
<?xml version="1.0" encoding="Windows-1252"?> <Database Name="Northwind"> <Table Name="Categories"> <Type Name="Mapping.Category"> <Column Name="CategoryID" Member="CategoryID" Storage="_CategoryID" DbType="Int NOT NULL IDENTITY" IsIdentity="True" IsAutoGen="True" /> <Column Name="CategoryName" Member="CategoryName" Storage="_CategoryName" DbType="NVarChar(15) NOT NULL" /> <Column Name="Description" Member="Description" Storage="_Description" DbType="NText" UpdateCheck="Never" /> <Column Name="Picture" Member="Picture" Storage="_Picture" DbType="Image" UpdateCheck="Never" /> <Association Name="FK_Products_Categories" Member="Products" Storage="_Products" ThisKey="CategoryID" OtherTable="Products" OtherKey="CategoryID" /> </Type> </Table> </Database>
The above code shows how the Categories table in the Northwind database could be mapped in an XML file. One thing of special note here is the Association element which will allow data hierarchies to be established, much like you can do in the DLINQ designer. You can generate this file by hand if you want, or you can use the new version of LINQ Preview\bin\sqlMetal.exe to generate the starting point for you. sqlMetal has a lot of options for you to look at, including a bunch to take save snapshots of database schema information to an xml file, and generate classes and XML mapping files from that saved XML file. A sample command would look like this:
sqlmetal /server:(local) /database:Northwind /map:nwindmapping.xml /namespace:Mapping /code:nwind.cs
The resulting nwind.cs file does not contain any attributes, as they are all stored in the xml file. To use this file, use code like this:
XmlMappingSource mappingSource = XmlMappingSource.FromXml(File.ReadAllText("nwindmapping.xml")); Mapping.Northwind db = new Mapping.Northwind("Integrated Security=SSPI;database=northwind;server=(local)", mappingSource); var q = from c in db.Categories select c.CategoryName; foreach (string s in q) listBox1.Items.Add(s);
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.