如何从映射空值终止ValueInjecter? [英] How do I stop ValueInjecter from mapping null values?

查看:218
本文介绍了如何从映射空值终止ValueInjecter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ValueInjecter绘制两个相同的对象。我遇到的问题是,从我的源超过我的目标ValueInjector拷贝空值。所以我失去大量的数据为空值。



下面是我的对象的一个​​例子是,有时只有一半填写从而导致其覆盖目标对象空值。

 公共类为MyObject()
{
公众诠释ID {搞定;组; }
公共字符串名称{;组; }
公共虚拟的ICollection< OtherObject> OtherObjects {搞定;组; }
}

to.InjectFrom(从);


解决方案

您需要创建在这种情况下,自定义ConventionInjection。见例子2:
的http:// valueinjecter.codeplex.com/wikipage?title=step%20by%20step%20explanation&referringTitle=Home



所以,你需要重写匹配方法:

 保护覆盖布尔匹配(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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆