LINQ到实体无​​法识别方法'System.String的ToString()“方法,而这种方法不能被翻译成店前pression [英] LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

查看:70
本文介绍了LINQ到实体无​​法识别方法'System.String的ToString()“方法,而这种方法不能被翻译成店前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下观点我的asp.net MVC应用程序内: -

  @model MvcApplication4.Models.ContactsDetails
     < H3>选择联系人Detials< / H3 GT&;
    < p =类dashboarder的风格=COLOR:#5c87b2><强> @ Model.Info.Count()< / STRONG>选择客户帐户< / P>
    @using(Html.BeginForm(导出,NULL))
    {
        INT32 C = -1;
        <表>
            &所述; TR>
                <第i个
                    账户名@ Html.CheckBox(IncludeAccountName,真)
                < /第i
                <第i个
                    名@ Html.CheckBox(IncludeName,真)
                < /第i

这是使用下面的操作方法填充: -

 公众的ActionResult CustomersDetails(长[] SelectRight)
{    如果(SelectRight == NULL)
    {
        返回RedirectToAction(客户,新的{ISERROR =真});
    }
    其他
    {        VAR ContactsDetails2 =新ContactsDetails
        {
            信息= r.getcontactinfo(SelectRight)
        };
        返回查看(ContactsDetails2);    }
}

,然后将下面的方法库: -

 公开的IEnumerable< AaaUserContactInfo> getcontactinfo(长[]号)
{
    VAR organizationNames = entities.SDOrganizations
                   。凡(ORG => id.Contains(org.ORG_ID))
                   。选择(ORG => org.NAME);
    VAR的结果=从userContactInfo在entities.AaaUserContactInfoes
                 加入CONTACTINFO在entities.AaaContactInfoes上userContactInfo.CONTACTINFO_ID等于contactInfo.CONTACTINFO_ID
                 其中,organizationNames.Contains(contactInfo.EMAILID.ToString())
                 选择userContactInfo;
    返回结果;

但是当我运行应用程序万亩我得到个...查看folloiwng不清的错误: -

  LINQ到实体无​​法识别方法'System.String的ToString()方法,而这种方法不能被翻译成店前pression。

在以下code: -

 <强> @ Model.Info.Count()< / STRONG>


解决方案

使用<一个href=\"http://msdn.microsoft.com/en-us/library/dd487127.aspx\"><$c$c>SqlFunctions.StringConvert方法代替的ToString (不能转换成SQL):

 其中organizationNames.Contains(SqlFunctions.StringConvert(contactInfo.EMAILID))

如果 EMAILID 不是双重或小数,那么只投值的类型之一。

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>

解决方案

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.

这篇关于LINQ到实体无​​法识别方法'System.String的ToString()“方法,而这种方法不能被翻译成店前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆