2009-11-28 44 views
0

即使是一个简单的查询像亚音速3.X:ArgumentException的同时查询(LINQ)

EmmaDatabase.EmmaDB ec = DatabaseProvider.GetEmmaDatabase(); 
var changes = (from o in ec.dbCachedChanges 
          select o); 

我抛出一个ArgumentException(参数类型不匹配),同时遍历它。 Stacktrace只包含

at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression) 

这完全没有帮助我。我不知道这是什么原因造成的,在这里没有发现任何东西,也没有使用Google搜索。

编辑:异常并没有改变结果,异常只是吃时间。

有人能帮助我吗?

回答

2

解决了,不是断路器,只是编写例外。

Subsonic.Core.Linq.Structures.QueryMapping.cs:155

if (me != null) 
{ 
    try { 
      bindings.Add(Expression.Bind(mi, me)); 
    } catch { 
     //this is only here until I rewrite this whole thing 
    } 
} 

可以通过

if (me != null) 
{ 
    try { 
     if (mi is PropertyInfo && ((PropertyInfo)mi).PropertyType.IsAssignableFrom(me.Type)) 
      bindings.Add(Expression.Bind(mi, me)); 
     else if (mi is FieldInfo && ((FieldInfo)mi).FieldType.IsAssignableFrom(me.Type)) 
      bindings.Add(Expression.Bind(mi, me)); 
    } catch { 
     //this is only here until I rewrite this whole thing 
    } 
} 

来解决,因为QueryMapper.GetMappedMembers()返回一个包含只PropertyInfos和FieldInfos列表。