2016-03-15 173 views
0

下面的一段代碼,我在LinqPad 4中使用了'Dynamics CRM LinqPad Driver'。它將針對CRM Online實例執行代碼。雖然,執行此代碼,我得到'不能隱式轉換類型'System.Linq.IQueryable'爲'UserQuery.Container1'。在突出顯示的BOLD行中存在明確的轉換(您是否缺少演員?)。無法將類型'System.Linq.IQueryable <T>'隱式轉換爲'T'

void Main() { 

string[] chosenOnes = { 
"[email protected]", 
"[email protected]", 
}; 

IQueryable<Container1> zVar = ContactSet.Where(a => a.EMailAddress1 == "[email protected]") 
           .Select(a => new Container1() { FullName = a.FullName }); 
foreach(string element in chosenOnes) 
    **zVar.Concat(new Container1[]{(ContactSet.Where(a => a.EMailAddress1 == element) 
      .Select(a => new Container1() { FullName = a.FullName }))});** 

zVar.Dump(); 
} 

// Define other methods and classes here 
public class Container1 
{ 
    public string FullName {get; set; } 
} 

enter image description here

回答

0

你的數組初始化的嘗試是不正確的。只需使用ToArray()代替:

zVar.Concat(
    ContactSet.Where(a => a.EMailAddress1 == element) 
       .Select(a => new Container1() { FullName = a.FullName }) 
       .ToArray() 
); 
相關問題