2009-11-28 26 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列表。