2016-01-06 42 views
0

我是C#和Lightswitch的新手,所以我的解釋可能有些複雜,我事先致歉。我有一個函數查詢(在代碼中)使用_SingleorDefault方法並返回!= null值。在調試模式中,我可以展開「結果視圖將枚舉IEnumerable」並查看與EntitySet的其餘部分一起返回的記錄。我如何在代碼中引用這個集合的成員?此查詢不返回結果到屏幕,因此Visual Collection方法返回空值。這是查詢。在代碼中提取結果Lightswitch查詢

IDataServiceQueryable<DUTFullView> query; 
     query = from DUTFullViewIDpass in this.DataWorkspace.AUTOData.DUTFullViews 
       where (DUTFullViewIDpass.DUTTypeID == v.DUTTypeID) 
       && (DUTFullViewIDpass.SN == v.SN) 
       select DUTFullViewIDpass; 

     if (query.SingleOrDefault() != null) 

Watch Window view

Response to proposed solution

回答

0

你應該foreach

IDataServiceQueryable<DUTFullView> query = (from DUTFullViewIDpass in this.DataWorkspace.AUTOData.DUTFullViews 
       where (DUTFullViewIDpass.DUTTypeID == v.DUTTypeID) 
       && (DUTFullViewIDpass.SN == v.SN) 
       select DUTFullViewIDpass).Take(1); 

if(!query.Any()) 
    return; 

foreach(var item in query) 
{ 
    // You could do your logic here 
    //var example = item.Property1 
} 
+0

想你的代碼示例遍歷,但是我不能DUTFullView訪問集合中的實體時,我引用'項目。 ' –

+0

當您調試代碼時,它會進入foreach? –

+0

爲了澄清我沒有嘗試進入調試。使用你的代碼示例...'foreach(var item in query) { var localVar = item.xxxx}'其中xxx應該拉下DUTFullView集合內的實體列表。 –