无法隐式转换类型System.Linq.IQueryable <t>&#39;到了&#39; T&#39;

时间:2016-03-15 01:19:10

标签: linq crm linqpad

遵循这段代码,我在LinqPad 4中使用了“动态CRM LinqPad驱动程序”。它将针对CRM Online实例执行代码。同时,执行此代码我无法隐式转换类型System.Linq.IQueryable&#39; to&#39; UserQuery.Container1&#39;。存在显式转换(您是否错过了演员?)&#39;在突出显示的BOLD行。

void Main() {

string[] chosenOnes = {
"oamaweral@abc.com",
"rflefel@abc.com",
};

IQueryable<Container1> zVar = ContactSet.Where(a => a.EMailAddress1 == "uiuiyh@abc.com")
                              .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

1 个答案:

答案 0 :(得分:0)

您的阵列初始化尝试不正确。只需使用ToArray()代替:

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