سؤال

I am trying to inject properties from ProductCategoryViewModel, which has Title and Id properties into ProductViewModel, which also has Title and Id properties (but for Product) and ProductCategoryTitle,ProductCategoryId for ProductCategory.

Nothing I tried so far works. The default injection overwrites Title and Id props in ProductViewModel and so does FlatLoopValueInjection.

This is such a common use case, is there a premade value injection for it?

هل كانت مفيدة؟

المحلول

I solved this using the following value injection

    public class ProductCategoryToProduct : ConventionInjection
{
    protected override bool Match(ConventionInfo c)
    {
        return c.TargetProp.Name.Equals(c.Source.Type.Name + c.SourceProp.Name) && c.SourceProp.Type.Equals(c.TargetProp.Type);
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top