title: Serialize via DataContract to an XML Writer
body: <p>I am fairly new to .NET, but have been working on this project for sometime now with very little progress and with the amount of classes it's becoming a bit overwhelming.</p>
  
  <p>OBJECTIVE: </p>
  
  <ol>
  <li><p>Generate data from Entity Framework Tables (supposed to be using LINQ)&lt;- LINQ seems to be working.</p></li>
  <li><p>Translate Data into XML &lt;-Not working at all</p></li>
  <li><p>Email if not working &lt;- This is working just fine-oddly enough lol;) </p></li>
  </ol>
  
  <p>Can anyone give me an example of code where you connect to an Entity and Serialize (possibly using generics if that's the best way) via DataContract to an XML Writer? As per the comment here is a sample of what i am going for. -- so let's also say that in this model we want to join the "DIRTYMIKE" table which includes "The Boys" as an object with a name to be extracted via xml and "CARS" Table in the PRIUS by id Obviously this is a theoretical set of entities but hopefully it gives someone a chuckle :)</p>
  
  <p>Here's some theoretical class i just whipped up - hope this explains more of what the goal is:</p>
  
  <pre><code> public class TheOtherGuys 
  {
      private static ILog log;
      private string theBoysWrapper;
      private int rowsRead = 0;
      private int outputRecords = 0;
      private bool warnings = false;
      private bool fatal = false;
      private bool fatalMsg = false;
      /// &lt;summary&gt;
      /// Next wrap the xml with a Document Wrapper and Element Wrapper
      /// &lt;/summary&gt;
     public TheOtherGuys(ILog log)
      {
  
          XmlDocument doc = new XmlDocument();
          XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
          doc.AppendChild(dec);//creates root
          XmlElement root = doc.CreateElement("DIRTYMIKE");
          doc.AppendChild(root);
          XmlElement nextElem = doc.CreateElement("THEBOYS");
          log = LogManager.GetLogger(this.GetType());
          if (log.IsDebugEnabled == true)
          {
              log.Debug(GetType().Name + ".Constructor(): enter");
          }
          //creates new xml Document and set up declaration and root
  
          if (log.IsDebugEnabled == true)
          {
              log.Debug(GetType().Name + ".Constructor(): exit");
          }
      }
      //Read data from DIRTY_MIKE_AND_THE_BOYS and CAR Tables
      //Translate the results into xml
      private void process(DateTime process) {
  
          XmlDocument doc = new XmlDocument();
          XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
          doc.AppendChild(dec);//creates root
          XmlElement root = doc.CreateElement("OTHERGUYS");//maybe  a conditional statement to          change the root to 'OTHERGUYS'
          doc.AppendChild(root);
          XmlElement nextElem = doc.CreateElement("CAR");
          doc.AppendChild(nextElem);
  
          if (log.IsDebugEnabled == true)
          {
              log.Debug(GetType().Name + ".process(): enter - prius=" + process);
          }
          StringBuilder sb = new StringBuilder();
          sb.Append(" select ");
          sb.Append("     'PRIUS' CAR, ");  // 1
          sb.Append("     'PJM' MKT_CD, ");      // 2
          sb.Append("     decode(to_char(lh.time_id-1/24, 'HH24'), '00',  ");
          sb.Append("            to_char(lh.time_id-1, 'YYYYMMDD'), to_char(lh.time_id-1/24, 'YYYYMMDD')) START_DT, ");   // 3
          sb.Append("     decode(to_char(lh.time_id-1/24, 'HH24'), '00',  ");
          sb.Append("            '240000', to_char(lh.time_id-1/24, 'HH24MISS')) START_TIME, "); //4
          sb.Append("     decode(to_char(lh.time_id, 'HH24'), '00',  ");
          sb.Append("            to_char(lh.time_id-1, 'YYYYMMDD'), to_char(lh.time_id, 'YYYYMMDD')) END_DT, ");  // 5
          sb.Append("     decode(to_char(lh.time_id, 'HH24'), '00',  ");
          sb.Append("            '240000', to_char(lh.time_id, 'HH24MISS')) END_TIME,      ");  // 6
          sb.Append("       cars._car_id            TX_PT,     ");  //8
          sb.Append("     lh.data_value TARGET_FD ");  // 12
          sb.Append("from DATABASE.MYTABLE lh,          ");
          sb.Append("     DATABASE.CAR car_id                         ");
          sb.Append("where lh.car_id = unit.car_id         ");
          sb.Append("AND lh.time_id &gt; to_date(?, 'MM/DD/YYYY') ");
          sb.Append("AND lh.time_id &lt;= to_date(?, 'MM/DD/YYYY' ) + 1 ");
          sb.Append("AND lh.atb_data_category = 69  AND lh.data_value &lt;&gt; 0        ");
          sb.Append(" order by ");
          sb.Append("     lh.time_id, lh.car_id ");
  
          sb.ToString();// or something like that 
         myDataLayer.theOtherGuysEntitie nme = new myDataLayer.theOtherGuysEntities(myConnection.getEntityFrameworkConnection(typeof(myDataLayer.theOtherGuysEntities)));
          if (log.IsDebugEnabled == true)
          {
              log.Debug(GetType().Name + ".process(): odb" + odb);
              try
              {
                  DateTime dt = DateTime.ParseExact(processingDate.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
                  string s = dt.ToString("dd/M/yyyy");
  
  
  
              }catch(Exception e) {
                  fatal=true;
                  fatalMsg = true;
                  if(log.IsFatalEnabled==true) {
                      log.Fatal(GetType().Name + ".process(): exception", e);
                  }
                  Console.Error.WriteLine("The OtherGuys Failed Dirty Mike is in the Prius with name{}, name{1}, name{2}, name {3}.");
       //Really I am supposed to use LINQ for the querying
      // and then conditionalstatementsthrough my business logic to handle the decoding 
  </code></pre>
  
  <p>Thanks Again!!</p>