I am writing a code to map certain properties from one object to another except the Navigational properties.
My code looks something like this:
var properties = typeof(TOne).GetProperties();
var t = new TOne();
foreach (var prop in properties)
{
var skip = exempt == null || (exempt != null && exempt.Contains(prop.Name));
if (!skip && CommonHelper.HasProperty(obj, prop.Name))
{
var _prop = obj.GetType().GetProperty(prop.Name);
CommonHelper.SetPropValue(t, prop.Name, _prop.GetValue(obj, null));
}
}
I would like to skip all the navigational properties (do not wish to copy object but primitive types).
For example:
class Person {
public int Id { get; set; }
[ForeignKey("DetailId")]
public Detail Detail { get; set; }
public int DetailId { get; set; }
}
I wish to copy DetailId but not the Detail object.