Reputation: 85
I have a DataRow object from a dealers DataTable which has columns d_id, d_name, d_contactInfo and a domain class object Dealer that has properties id, name, contactInfo. I am looking for a way to convert this dataRow to the domain class object by using a conversion such as
DbDataSet.dealers.FindByd_id(id) as Dealer;
Is there some way I can achieve this? because if so, the code would look MUCH cleaner than having to specify attribute mapping one by one. Thanks.
Upvotes: 0
Views: 547
Reputation: 17010
You have a couple of options to solve this. One is to create your own data layer object that maps the fields in the DataRow to an object. If you want this more automagic, you can either create a helper routine, or if you can get the data out as XML or JSON, you can use serialization to match the items. This is the harder way to accomplish this.
If you can refactor the code, you can use Entity Framework to match the items. I am not as fond of it in Enterprise scale code, but it works fine with others. There are other OR/M products, many open source, that can do it as well. Chosing the correct one depends on your requirements (some are faster, some have more features, etc.)
There are also products that can map from one shape to another and save you some time, as is mentioned in the comments.
Upvotes: 1