Data Platform Developer Center >
Data Platform Development Forums
>
ADO.NET DataSet
>
DataRow to Custom Object
DataRow to Custom Object
- 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
- 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- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, November 04, 2009 7:38 AM
- Proposed As Answer byDharmalinga Raja Monday, November 02, 2009 12:37 PM
All Replies
- 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. - 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- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, November 04, 2009 7:38 AM
- Proposed As Answer byDharmalinga Raja Monday, November 02, 2009 12:37 PM
- Hi,
Thank you very much for your reply. I will look up some information on the Data Services libraries. - Hi,
Thank you for your reply and code sample. I will implement it in my project and view the results. Once again, thank you.


