Ask a questionAsk a question
 

AnswerDataRow to Custom Object

  • Tuesday, October 06, 2009 2:41 PMGiovanniP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dear Friends,

         I have built a custom class with the Serializable and several XMLElement attributes as I need to serialize this class to XML as and end result.  I am using a typed DataSet with typed DataRows.  My issue is that I would like to automatically convert a DataRow or (a set of DataRows) to an instance (or instances) of my custom object.  I am not too sure about how to go about this.  I am NOT using the Entities Framework as I am not familiar with it yet.  Is there a way that LINQ can be used to automatically convert a DataRow to an instance of my custom object?  I would hope that if I use the SAME field names in the DataRow as my custom class, then maybe it would map the information automatically.  Any help would be greatly appreciated.

         Giovanni

Answers

  • Monday, November 02, 2009 12:10 PMNarayanan Dayalan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Dim ds = new DataSet()
    FillOrders(ds, myConnectionString)

    Dim orders = ds.Tables("SalesOrderHeader").ToQueryable()
    Dim orderLines = ds.Tables("SalesOrderDetail").ToQueryable()

    Dim query = From o In orders _
                Where o!OnlineOrderFlag = True _
                Select SalesOrderID := o!SalesOrderID, _
                       OrderDate := o!OrderDate

    Narayanan Dayalan - Zeetaa Business Solutions Please Mark "Propose As Answer", if my answer works well with ur Query

All Replies

  • Monday, November 02, 2009 6:46 AMtechnocrat_aspire Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Take a look at the ADO.NET Data Service. It does convert each of your datarow to your object and returns that over rest. Let me know if it helps.
  • Monday, November 02, 2009 12:10 PMNarayanan Dayalan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Dim ds = new DataSet()
    FillOrders(ds, myConnectionString)

    Dim orders = ds.Tables("SalesOrderHeader").ToQueryable()
    Dim orderLines = ds.Tables("SalesOrderDetail").ToQueryable()

    Dim query = From o In orders _
                Where o!OnlineOrderFlag = True _
                Select SalesOrderID := o!SalesOrderID, _
                       OrderDate := o!OrderDate

    Narayanan Dayalan - Zeetaa Business Solutions Please Mark "Propose As Answer", if my answer works well with ur Query
  • Monday, November 02, 2009 7:46 PMGiovanniP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

         Thank you very much for your reply.  I will look up some information on the Data Services libraries.
  • Monday, November 02, 2009 7:47 PMGiovanniP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

         Thank you for your reply and code sample.  I will implement it in my project and view the results.  Once again, thank you.