2013-01-04 32 views
2

我有asp.net MVC应用程序内的下面的视图: -LINQ到实体无法识别方法“System.String的ToString()”方法,和这种方法不能被翻译成表达商店

@model MvcApplication4.Models.ContactsDetails 
    <h3>Select Contacts Detials</h3> 
    <p class="dashboarder" style = "color:#5c87b2"><strong>@Model.Info.Count()</strong> Selected Customers Accounts.</p> 
    @using (Html.BeginForm("Export", null)) 
    { 
     Int32 c = -1; 
     <table> 
      <tr> 
       <th> 
        Account Name @Html.CheckBox("IncludeAccountName", true) 
       </th> 
       <th> 
        Name @Html.CheckBox("IncludeName", true) 
       </th> 

其使用下列操作方法填充: -

public ActionResult CustomersDetails(long[] SelectRight) 
{ 

    if (SelectRight == null) 
    { 
     return RedirectToAction("customer", new { isError = true }); 
    } 
    else 
    { 

     var ContactsDetails2 = new ContactsDetails 
     { 
      Info = r.getcontactinfo(SelectRight) 
     }; 
     return View(ContactsDetails2); 

    }   


} 

然后将下面的储存库方法: -

public IEnumerable<AaaUserContactInfo> getcontactinfo(long[] id) 
{ 
    var organizationNames = entities.SDOrganizations 
        .Where(org => id.Contains(org.ORG_ID)) 
        .Select(org => org.NAME); 


    var result = from userContactInfo in entities.AaaUserContactInfoes 
       join contactInfo in entities.AaaContactInfoes on userContactInfo.CONTACTINFO_ID equals contactInfo.CONTACTINFO_ID 
       where organizationNames.Contains(contactInfo.EMAILID.ToString()) 
       select userContactInfo; 
    return result; 

但是当我运行亩应用我得到第视图上folloiwng不清楚错误: -

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. 

上下面的代码: -

<strong>@Model.Info.Count()</strong> 

回答

5

使用SqlFunctions.StringConvert方法代替ToString(其不能被转换到SQL):

where organizationNames.Contains(SqlFunctions.StringConvert(contactInfo.EMAILID)) 

如果EMAILID没有增加一倍或小数,那么只投值到一个这些类型。

相关问题