<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Buy Aziswift (Zithromax) Without Prescription</title> <atom:link href="http://quickduck.com/blog/tag/xmlreader/feed/" rel="self" type="application/rss+xml" /><link>http://quickduck.com/blog</link> <description>Straight from the mind of geniuseseses....</description> <lastBuildDate>Mon, 05 Mar 2012 22:26:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Buy Aziswift (Zithromax) Without Prescription</title><link>http://quickduck.com/blog/2008/02/15/using-xmlreader-to-go-from-sql-result-set-to-a-list-of-objects/</link> <comments>http://quickduck.com/blog/2008/02/15/using-xmlreader-to-go-from-sql-result-set-to-a-list-of-objects/#comments</comments> <pubDate>Fri, 15 Feb 2008 10:31:27 +0000</pubDate> <dc:creator>@benpriebe</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Sql Server]]></category> <category><![CDATA[Data Access]]></category> <category><![CDATA[XmlReader]]></category><guid isPermaLink="false">http://quickduck.com/blog/2008/02/15/using-xmlreader-to-go-from-sql-result-set-to-a-list-of-objects/</guid> <description><![CDATA[Buy Aziswift (Zithromax) Without Prescription, These days there seems to be an infinte number of ways to take data returned from the database and map them into your object model. This article aims to simple show you how to generically map the sql select result set into a list of object instances in your code, [...]]]></description> <content:encoded><![CDATA[<p> <b>Buy Aziswift (Zithromax) Without Prescription</b>, These days there seems to be an infinte number of ways to take data returned from the database and map them into your object model.</p><p>This article aims to simple show you how to generically map the sql select result set into a list of object instances in your code, <b>Aziswift (Zithromax) blogs</b>. <b>Where can i buy cheapest Aziswift (Zithromax) online</b>, First things first, the code illustrated here requires Sql Server 2005, <b>Aziswift (Zithromax) no rx</b>, <b>Is Aziswift (Zithromax) addictive</b>, and .Net 2.0+ framework.</p><p><h2>Sql Server 2005 Queries</h2></p><p>It doesn't matter whether you write you queries in code or by using Sql Server SProcs, <b>Aziswift (Zithromax) treatment</b>, <b>Online buying Aziswift (Zithromax)</b>, simple by adding - 'FOR XML Path('ElementName') - the following to the end of you Select statement, Sql Server will return your result sets in Xml, <b>order Aziswift (Zithromax) online overnight delivery no prescription</b>. <b>Canada, mexico, india</b>,<pre><code><br />
Syntax:</p>
<p>SELECT * FROM [TableName] WITH (nolock) FOR XML PATH('TableName')</p>
<p></code></pre></p><p><pre><code><br />
Example:</p>
<p>SELECT * FROM [Channel] WITH (nolock) FOR XML PATH('Channel')</p>
<p>Results:</p>
<p>&lt;Channel&gt;<br />
  &lt;Id&gt;1&lt;/Id&gt;<br />
  &lt;Type&gt;web&lt;/Type&gt;<br />
  &lt;Description&gt;standard internet&lt;/Description&gt;<br />
&lt;/Channel&gt;<br />
&lt;Channel&gt;<br />
  &lt;Id>3&lt;/Id&gt;<br />
  &lt;Type>mobile&lt;/Type&gt;<br />
  &lt;Description>mobile&lt;/Description&gt;<br />
&lt;/Channel&gt;</p>
<p></code></pre></p><p>The parameter passed into the Path() statement determines the top level element name - allowing you to shape the xml.</p><p><h2>The Entity POCOs</h2></p><p>Using the .Net built in xml to class deserialization process, the returned xml will map the top level element to a class name and each sub-element to a public property/member on the object class, <b>Buy Aziswift (Zithromax) Without Prescription</b>.</p><p>Let's create the Plain Old C# Object to enable deserialization, <b>where to buy Aziswift (Zithromax)</b>. <b>Aziswift (Zithromax) without a prescription</b>,<pre><code><br />
/// Represents a media channel (e.g. web, <b>taking Aziswift (Zithromax)</b>, <b>Cheap Aziswift (Zithromax)</b>, mobile, iphone, <b>where can i buy Aziswift (Zithromax) online</b>, <b>Aziswift (Zithromax) duration</b>, etc.)<br />
public class Channel    {<br />
  private int _id;<br />
  private string _type, _description;</p>
<p>  public Channel(){}</p>
<p>  public Channel(string type, <b>Aziswift (Zithromax) pharmacy</b>, <b>Generic Aziswift (Zithromax)</b>, string description)  {<br />
    _type = type;<br />
    _description = description;<br />
  }</p>
<p>  /// Get/Set the channel identifier<br />
  public int Id {<br />
    get { return _id; }<br />
    set { _id = value; }<br />
  }</p>
<p>  /// Get/Set the channel type (e.g. web, <b>no prescription Aziswift (Zithromax) online</b>, <b>Aziswift (Zithromax) without prescription</b>, mobile, iphone, <b>order Aziswift (Zithromax) online c.o.d</b>, <b>Aziswift (Zithromax) used for</b>, etc.)<br />
  public string Type {<br />
    get { return _type; }<br />
    set { _type = value; }<br />
  }</p>
<p>  /// Get/Set the description of the channel.<br />
  public string Description {<br />
    get { return _description; }<br />
    set { _description = value; }<br />
  }<br />
}<br />
</code></pre></p><p><strong>NOTE:</strong> <b>Buy Aziswift (Zithromax) Without Prescription</b>, If there are differences in your database schema naming conventions to how you name things in your classes you will need to shape the xml somewhere to make the deserialization process work.</p><p>You have two options: you can decorate your class with appropriate Xml Serialization Attributes <strong>OR</strong> you can change your Sql Query, <b>herbal Aziswift (Zithromax)</b>. <b>Aziswift (Zithromax) natural</b>, Example: the Channel table has a column name <em>desc</em> but you need to map to the public property name <em>Description</em>.</p><p><strong>Scenario 1:</strong> Shape the xml using the [XmlAttribute]</p><p><pre><code><br />
  [XmlAttribute("desc")]<br />
  public string Description {<br />
    get { return _description; }<br />
    set { _description = value; }<br />
  }<br />
</code></pre></p><p>OR</p><p><strong>Scenario 2:</strong> Shape the xml in your Sql Query<br /><pre><code><br />
SELECT [Id], <b>Aziswift (Zithromax) pictures</b>, <b>Buy generic Aziswift (Zithromax)</b>, [Type], [Desc] as Description<br />
FROM [Channel]<br />
WITH (nolock)<br />
FOR XML PATH('Channel')<br />
</code></pre></p><p><h2>Data Access Code</h2></p><p>Ok, <b>Aziswift (Zithromax) street price</b>. <b>Discount Aziswift (Zithromax)</b>, You know how to get the data back from the DB in Xml. Now it's time to read the results into a list of the entity POCOs, <b>Buy Aziswift (Zithromax) Without Prescription</b>.</p><p><pre><code><br />
  private static readonly IDictionary<Type, <b>comprar en línea Aziswift (Zithromax), comprar Aziswift (Zithromax) baratos</b>, <b>Buy Aziswift (Zithromax) from canada</b>, XmlSerializer> xmlSerializers = new Dictionary<Type, XmlSerializer>();</p>
<p>  /// Generic helper method for reading sql server table rows into entities, <b>australia, uk, us, usa</b>.  <b>Aziswift (Zithromax) from mexico</b>, internal IList<T> GetEntities<T>(DbCommand dbCommand)  {<br />
    IList<T> entities = new List<T>();<br />
    using (XmlReader reader = ((SqlDatabase) Database).ExecuteXmlReader(dbCommand))  {<br />
      while (!reader.EOF) {<br />
        if (reader.IsStartElement()) {<br />
          entities.Add(Deserialize<T>(reader.ReadOuterXml()));<br />
        }<br />
      }<br />
    }<br />
    return entities;<br />
  }</p>
<p></p>
<p>  /// Deserialize an xml fragment into the specified Type.<br />
  public T Deserialize<T>(string xml)  {<br />
    using (StringReader sr = new StringReader(xml)) {<br />
      if (!xmlSerializers.ContainsKey(typeof (T))){<br />
        xmlSerializers.Add(typeof (T), <b>buying Aziswift (Zithromax) online over the counter</b>, <b>Buy Aziswift (Zithromax) without prescription</b>, new XmlSerializer(typeof (T), null, <b>Aziswift (Zithromax) dose</b>, <b>Aziswift (Zithromax) no prescription</b>, new Type[0], null, <b>Aziswift (Zithromax) without a prescription</b>, null));<br />
      }<br />
      XmlSerializer serializer = xmlSerializers[typeof (T)];<br />
      return (T) serializer.Deserialize(sr);<br />
    }<br />
  }<br />
</code></pre></p><p><strong>NOTE:</strong> I cache an XmlSerialzer instance for each Type because the .Net framework generates a class dynamically at runtime when the new XmlSerializer() constructor is called. If you have thousands of results coming back from the DB this is timely and memory consuming.</p><p><h2>Usage Examples:</h2></p><p><pre></code> <b>Buy Aziswift (Zithromax) Without Prescription</b>, /// Get a specific Channel.<br />
public Channel GetChannel(string name) {<br />
  IList<Channel> list = GetEntities<Channel>(Database.GetStoredProcCommand("usp_GetChannels", 0, name));<br />
  return (list != null && list.Count == 1) . list[0] : null;<br />
}</p>
<p>/// Get a list of all Channels.<br />
public IList<Channel> GetChannels() {<br />
  return GetEntities<Channel>(Database.GetStoredProcCommand("usp_GetChannels", 0, null));<br />
}<br />
</code></pre></p><p>That's it.</p><p><strong>Update: 18-Feb-08</strong> I've written a followup article that shows how to do the reverse process - <a href="http://quickduck.com/blog/2008/02/18/persisting-objects-into-database-using-xml-serialization/">Persisting objects into database using xml serialization</a>.</p><p></p><p><b>Similar posts:</b> <a href='http://quickduck.com/blog/?p=42'>Finara (Propecia) For Sale</a>. <a href='http://quickduck.com/blog/?p=73'>Proscar (Propecia) For Sale</a>. <a href='http://quickduck.com/blog/?p=57'>Buy Finalo (Propecia) Without Prescription</a>. <a href='http://quickduck.com/blog/?p=402'>My Albuterol (Ventolin) experience</a>. <a href='http://quickduck.com/blog/?p=4'>Where can i order Ultram ER (Tramadol) without prescription</a>. <a href='http://quickduck.com/blog/?p=12'>Get Hiconcil (Amoxicillin)</a>.<br /> <b>Trackbacks from:</b> <a href='http://weblog.cazucito.com/?p=740'>Buy Aziswift (Zithromax) Without Prescription</a>. <a href='http://www.wolcf.org/?p=1686'>Buy Aziswift (Zithromax) Without Prescription</a>. <a href='http://therustbox.com/blog/?p=332'>Buy Aziswift (Zithromax) Without Prescription</a>. <a href='http://www.leahey.org/?p=538'>After Aziswift (Zithromax)</a>. <a href='http://bassfishingheaven.com/?p=4970'>Aziswift (Zithromax) treatment</a>. <a href='http://duffoto.com/randomnoise/?p=499'>Aziswift (Zithromax) mg</a>.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2008/02/15/using-xmlreader-to-go-from-sql-result-set-to-a-list-of-objects/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: quickduck.com @ 2012-05-22 12:14:30 -->
