reflection

Mapping DataTables and DataRows to Objects in C# and .NET

My group regularly uses DataSet, DataTable, and DataRow objects in many of our apps. (What? Don't look at me like that. These apps are old.) Anyway, we're simultaneously trying to implement good C# and object-oriented programming principles while maintaining these old apps, so we often end up having to map data from a data set to a C# object. We did this enough times that I and a coworker (we'll call her Marlena) decided to sit down and just make... Read more >

Object Change Tracking via Reflection in .NET

We have this big project we're working on (which I have written about before) and one of the things we need to do on this project is automatic logging of changes made to model objects. I've worked out a way to do this generically, for any object, and I think others might find it just as useful as we have. Requirements We needed to be able to compare two objects of the same type, examine their properties, and log which... Read more >

Loading Entity Framework Related Entities with AutoMapper and Reflection

In a previous post I mentioned how we would be using AutoMapper to create Data-Transfer Objects out of Entity Framework entities; the DTOs would then be transmitted over a WCF service. Well, as often happens, a new requirement surfaced recently, and the solution we came up with turned out to be pretty useful, so now I'm sharing it with you all. The Problem The issue we had was this: because this app needs to keep performance in mind (and because... Read more >

Using .NET Reflection to Map DataTables to Strongly-Typed Models

NOTE: I've got a more thorough version of this post up at Mapping DataTables and DataRows to Objects in C# using Reflection. Check it out! We're in the process of converting an old ASP.NET WebForms application to MVC. For this particular project, we are accessing an old database, one that doesn't really play well with Entity Framework or other ORMs, so we're using ADO.NET statements to get the data back in the form of DataTables. DataTables, however, are... Read more >

Mapping an MVC ViewModel to a List of Name/Value Pairs

An interesting scenario came up at work the other day. I have a class (corresponding to a database table) which can store any piece of data in a name-value pair. This is so we can store any number of pieces of "incidental" information in our database that is shared among many web apps. That class looked like this: public class DataPair { public string Name { get; set; } public string Value { get; set; } } Now what I need is for a... Read more >
/* * * DON'T EDIT BELOW THIS LINE * * */ (function () { var s = document.createElement('script'); s.async = true; s.type = 'text/javascript'; s.src = '//' + disqus_shortname + '.disqus.com/count.js'; (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); }());