鉴于此方法:
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;
}
而这个帮手:
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;
}
我在我的 linq 语句中遇到了这个异常:
无法识别的方法调用:System.Collections.Generic.EqualityComparer`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]:Boolean Equals(System.Guid, System.Guid)
这是什么意思?我什至不确定如何正确调试它。我可以发誓上面的代码正在工作......