EdisonCP / sharp-architecture

Automatically exported from code.google.com/p/sharp-architecture
Other
0 stars 0 forks source link

EntityDuplicateChecker should fully support EntityWithTypedId<IdT> #127

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This was originally reported and fixed as Issue 118, but I have determined 
that the fix was inadequate (partially due to my incorrect suggestion). 

Please see issue 118 for the original problem description.
http://code.google.com/p/sharp-architecture/issues/detail?id=118

I suggested the following fix:
else if (propertyType.IsSubclassOf(typeof(IEntityWithTypedId<IdT>))) {
    AppendEntityCriteriaTo(criteria, signatureProperty, propertyValue);
}

Unfortunately, I didn't know that IsSubclassOf does not support interfaces. 
Please see:
http://msdn.microsoft.com/en-us/library/system.type.issubclassof.aspx

So the fix should be:
else if (propertyType.IsSubclassOf(typeof(EntityWithTypedId<IdT>))) {
    AppendEntityCriteriaTo<IdT>(criteria, signatureProperty, 
propertyValue);
}

Also, the AppendEntityCriteriaTo method needs to be updated to reflect 
checking of the different type:

if (propertyValue != null) {
    criteria.Add(Expression.Eq(signatureProperty.Name + ".Id",
        ((EntityWithTypedId<IdT>)propertyValue).Id));
}

We require the type of Id now, so the method signature must be changed to:

private static void AppendEntityCriteriaTo<IdT>(ICriteria criteria, 
PropertyInfo signatureProperty, object propertyValue)

Original issue reported on code.google.com by goo...@deap.ca on 15 Sep 2009 at 11:15

GoogleCodeExporter commented 8 years ago

Original comment by wmccaffe...@gmail.com on 30 Sep 2009 at 9:08

GoogleCodeExporter commented 8 years ago
Thanks for the re-fix!  I made a slight modification to support all 
IEntityWithTypedId<>:

else if (propertyType.GetInterfaces()
    .Any(x => x.IsGenericType && 
         x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>))) {
    AppendEntityCriteriaTo<IdT>(criteria, signatureProperty, propertyValue);
}

and

criteria.Add(Expression.Eq(signatureProperty.Name + ".Id",
    ((IEntityWithTypedId<IdT>)propertyValue).Id));

(Will be checking in the solution shortly for the Q3 release.)

Original comment by wmccaffe...@gmail.com on 29 Oct 2009 at 9:27