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

asp.net-mvc c# entity-framework linq

Question

I have the following view inside my asp.net mvc application:-

 @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>

which is populated using the following action method:-

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);

    }          


}

and then the following repository method:-

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;

but when i run mu application i got th folloiwng unclear error on the view :-

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

on the following code:-

<strong>@Model.Info.Count()</strong>
1
2
1/4/2013 1:19:02 AM

Accepted Answer

Use SqlFunctions.StringConvert method instead of ToString (which cannot be converted into SQL):

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

If EMAILID is not double or decimal, then just cast value to one of those types.

5
1/4/2013 1:13:42 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow