Thoughts from Dan Miser RSS 2.0
# Tuesday, May 16, 2006
In the README for the LINQ download, one big feature that was mentioned was the ability to use an external XML mapping file instead of attributes. This decouples the schema information from the code, which is good as a database schema tends to change over time, and you don't want to recompile every time your DBA decides to change something on you. The down side is that there isn't much information out there on how to get it to work. Hopefully, this entry fills that gap.

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);
Tuesday, May 16, 2006 7:10:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [2] -
LINQ
Tracked by:
"sqlMetal mapping file generation requires namespaces" (Dan Miser) [Trackback]
"sqlMetal mapping file generation requires namespaces" (Dan Miser) [Trackback]
http://www.distribucon.com/blog/PermaLink,guid,c8b863ee-0371-4d97-92dc-8f15d38d4... [Pingback]
http://www.distribucon.com/blog/PermaLink,guid,4c37ea38-52be-4343-bf15-2c4ba46ae... [Pingback]
http://9no-information.info/26266821/crazy-horse-canoeing.html [Pingback]
http://9nh-information.info/40855003/florida-ebay-seller.html [Pingback]
http://9nq-information.info/07955086/index.html [Pingback]
http://9nl-information.info/53522691/index.html [Pingback]
http://9nc-information.info/91043123/sports-chairs.html [Pingback]
http://9nw-information.info/69403901/index.html [Pingback]
http://9nt-information.info/16741238/index.html [Pingback]
http://9nt-information.info/71436764/anna-rose-travel-in-hanover-nh.html [Pingback]
http://9nd-information.info/97815972/forrester-s-chambersburg-cars.html [Pingback]
http://9nn-information.info/07670927/history-of-the-hummer-car.html [Pingback]
http://9qt-information.info/59659459/ricci-foto.html [Pingback]
http://9ov-information.info/55873493/index.html [Pingback]
http://9or-information.info/79850869/index.html [Pingback]
http://9ok-information.info/61460186/gree-racing-games.html [Pingback]
http://9qb-information.info/46824328/index.html [Pingback]
http://9oa-information.info/23505190/index.html [Pingback]
http://9qj-information.info/71923209/dell-color-printer-cartridge.html [Pingback]
http://9rc-information.info/47006209/index.html [Pingback]
http://9rt-information.info/67025865/index.html [Pingback]
http://9rj-information.info/12137910/index.html [Pingback]
http://9sb-information.info/93266101/index.html [Pingback]
http://9ra-information.info/54586894/index.html [Pingback]
http://9rk-information.info/66304938/eureka-ca-garden-center.html [Pingback]
http://9rf-information.info/70192191/index.html [Pingback]
http://9rj-information.info/03270191/index.html [Pingback]
http://9rw-information.info/71752556/index.html [Pingback]
http://9uaee-le-informazioni.info/46219310/index.html [Pingback]
http://9uaeq-le-informazioni.info/66780668/cartolina-animate-buon-natale.html [Pingback]
http://9uaef-le-informazioni.info/33012247/fotocamera-nokia-cellulare.html [Pingback]
http://9uafo-le-informazioni.info/25643064/sunto-leggi-mercato.html [Pingback]
http://9uaen-le-informazioni.info/40165992/maculan-breganze.html [Pingback]
http://9uaff-le-informazioni.info/04264010/index.html [Pingback]
http://9uaet-le-informazioni.info/30420436/index.html [Pingback]
http://9uaeo-le-informazioni.info/35533570/medico-it.html [Pingback]
http://9uaep-le-informazioni.info/96368568/index.html [Pingback]
http://9uaeg-le-informazioni.info/40819629/index.html [Pingback]
http://9uaej-le-informazioni.info/43307209/index.html [Pingback]
http://9uahk-le-informazioni.info/97081707/gevelsberg.html [Pingback]
http://9uahk-le-informazioni.info/92165145/corso-front-page.html [Pingback]
http://9uagp-le-informazioni.info/46381182/death-vegas-mp3.html [Pingback]
http://9uagt-le-informazioni.info/21851019/index.html [Pingback]
http://9uaga-le-informazioni.info/65222165/uscite-bassa-pressione-cressi.html [Pingback]
http://9uahj-le-informazioni.info/05557242/compagno-fidanzato-uomo.html [Pingback]
http://9uags-le-informazioni.info/94872336/antica-trattoria-della-pesa.html [Pingback]
http://9uagg-le-informazioni.info/96971568/d-lgs-196-2003-pdf.html [Pingback]
http://9uagk-le-informazioni.info/36072127/index.html [Pingback]
Navigation
Archive
<October 2014>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)