问题描述
我使用ValueInjecter绘制两个相同的对象。我遇到的问题是,从我的源超过我的目标ValueInjector拷贝空值。所以我失去大量的数据为空值。
下面是我的对象的一个例子是,有时只有一半填写从而导致其覆盖目标对象空值。
公共类为MyObject()
{
公众诠释ID {搞定;组; }
公共字符串名称{;组; }
公共虚拟的ICollection< OtherObject> OtherObjects {搞定;组; }
}
to.InjectFrom(从);
您需要创建在这种情况下,自定义ConventionInjection。见例子2:
所以,你需要重写匹配方法:
保护覆盖布尔匹配(ConventionInfo C){
//使用ConventionInfo参数访问源属性值
//例如,如果属性值不为null返回true。
}
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:
protected override bool Match(ConventionInfo c){
//Use ConventionInfo parameter to access the source property value
//For instance, return true if the property value is not null.
}
这篇关于如何从映射空值终止ValueInjecter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!