I am using ValueInjecter to map two identical objects. The problem I am having is that ValueInjector copies null values from my source over my target. So I am loosing lots of data to null values.
Here's an example of my object which is sometimes only half filled out which results in its null values overwriting the target object.
public class MyObject()
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<OtherObject> OtherObjects { get; set; }
}
to.InjectFrom(from);
You need to create a custom ConventionInjection in this case. See example #2: http://valueinjecter.codeplex.com/wikipage?title=step%20by%20step%20explanation&referringTitle=Home
So, you'll need to override the Match method:
You want something like this.
Usage:
For those using
ValueInjecter
v3+,ConventionInjection
has been deprecated. Use following to achieve same results:Usage: