Trying to create a data access component by mapping fields from an an oracle database to properties on an object. I've created a base object that takes a type and is called like this...
public class Document : DataProviderBase<DataObjects.Document>
{
// code goes here...
}
This base object has a method called AddMapping that maps database fields to properties like this...
this.AddMapping<int>("ATD_KEY", "Key")
In this case...
intis the type of propertyATD_KEYis the field name in the databaseKeyis the property name onDataObjects.Document
The code uses...
typeof(<TParent>).GetProperty(<property name>)
..to get PropertyInfo which is used to get and set the property.
While this is great, I would like to add a bit of type safety and lambda expressions to the AddMapping method. I'd like to do something like the following...
this.AddMapping<int>("ATD_KEY", o => o.Key)
..where o is of the type provided by DataProviderBase. This will ensure that property Key is actually of type int and ensures that the string "Key" is not misspelt or the wrong case as is a problem with the current working code shown in the 1st AddMapping method.
Is this possible? if so how?
The closest example I've found is this Dynamic Expression from the Property of the object of the class, however this still refers to the property by string and not by expression.