2017-06-27 69 views
0

ptemod是返回tElementRowValuesDBModel型無論是在內存中的查詢。直到此陳述出現之後,兩者纔會執行。LINQ查詢左連接多個列與空檢查失敗

如果我單獨調試並查看返回的結果,則成功運行並返回值。

我可以使用Exceptnot in子查詢,當然!但我只是想了解這是一個錯誤還是有解決方法。

奇怪的是,如果我刪除的tempe對象的任何引用,一切運行正常。 我錯過了什麼嗎?

var RealNewNodes = from p in pt 
        join e1 in emod on new{X1 = p.tElementRowsDBModelID, X2 = p.tAttributesDBModelID, X3 = p.AttributeValue} equals new {X1 = e1.tElementRowsDBModelID, X2 = e1.tAttributesDBModelID, X3 = e1.AttributeValue } into tempt 
        from tempe in tempt.DefaultIfEmpty() 
        where tempe == null //if i remove this line, works OK 
        select new tElementRowValuesDBModel{ 
         tElementRowsDBModelID = p.tElementRowsDBModelID, 
         tAttributesDBModelID = p.tAttributesDBModelID, 
         AttributeValue = p.AttributeValue, 
         ID = (tempe!=null ? 1 : 0)//if i remove this line, works OK 
        }; 
+0

以何種方式是失敗的? –

+0

@RomanoZumbé對象引用未設置爲對象的實例 –

+0

此EF Core?如果是,什麼版本? –

回答

0

或許,如果你沒有做的加入,因爲你的join/where手段找到pt沒有火柴,它會工作:

var RealNewNodes = from p in pt 
       where !emod.Any(e1 => p.tElementRowsDBModelID == e1.tElementRowsDBModelID && p.tAttributesDBModelID == e1.tAttributesDBModelID && p.AttributeValue == e1.AttributeValue) 
       select new tElementRowValuesDBModel { 
        tElementRowsDBModelID = p.tElementRowsDBModelID, 
        tAttributesDBModelID = p.tAttributesDBModelID, 
        AttributeValue = p.AttributeValue, 
        ID = 1 
       }; 
+0

謝謝,還沒有能夠嘗試它,會讓你知道,如果這工作儘快作品允許 –

+0

我發誓...我只好重新啓動我的電腦和我的原問題現在工作正常......但是這個答案也提供了相同的結果。謝謝 –