Given this method:
internal static IEnumerable<Entity> GetByParentImpl<Entity, TKey>(this ICanGetByParent<Entity, TKey> self, TKey parentId, string fieldName)
where Entity : class
{
RepositoryBase<Entity> rb = (RepositoryBase<Entity>)self;
rb.unitOfWork.Begin();
var entities = rb.unitOfWork.Session.QueryOver<Entity>()
.Where(e => EqualityComparer<TKey>.Default.Equals(GetId<Entity, TKey>(e, fieldName), parentId))
.List();
return entities;
}
And this assistant:
private static TKey GetId<Entity, TKey>(object obj, string fieldName) where Entity : class
{
TKey id = default(TKey);
switch(id.GetType().Name) {
case "Int32":
break;
case "Guid":
id = (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString((string)typeof(Entity).GetField(fieldName).GetValue(obj));
break;
}
return id;
}
I get this exception in my linq expression:
Unrecognized method call: System.Collections.Generic.EqualityComparer`1 [[System.Guid, mscorlib, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = b77a5c561934e089]]: Boolean Equals (System.Guid, System.Guid)
What does it mean? I'm not even sure how to properly debug this. I could swear the code above works ...
source
share