LINQ to Entities不能识别方法'System.String ToString()'方法,而且这种方法不能被转换成存储表达式 [英] LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
本文介绍了LINQ to Entities不能识别方法'System.String ToString()'方法,而且这种方法不能被转换成存储表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@model MvcApplication4.Models.ContactsDetails
< h3>选择联系人Detials< / h3>
< p class =dashboarderstyle =color:#5c87b2>< strong> @ Model.Info.Count()< / strong>所选客户帐户。< / p>
@using(Html.BeginForm(Export,null))
{
Int32 c = -1;
< table>
< tr>
< th>
帐户名称@ Html.CheckBox(IncludeAccountName,true)
< / th>
< th>
Name @ Html.CheckBox(IncludeName,true)
< / th>
使用以下操作方法填充: -
public ActionResult CustomersDetails(long [] SelectRight)
{
if(SelectRight == null)
{
返回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 entityContactInfo in entities.AaaUserContactInfoes
将entityInfo加入实体.AaaContactInfoes on userContactInfo.CONTACTINFO_ID等于contactInfo.CONTACTINFO_ID
其中organizationNames.Contains(contactInfo。 EMAILID.ToString())
select userContactInfo;
返回结果;
但是当我运行mu应用程序时,我看到了folloiwng不清楚的错误: -
LINQ to Entities不会识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式。
在以下代码: -
<强> @ Model.Info.Count()< /强>
解决方案
使用 SqlFunctions.StringConvert
方法,而不是 ToString
(不能转换为SQL):
其中organizationNames.Contains(SqlFunctions.StringConvert contactInfo.EMAILID))
如果 EMAILID
不是double或decimal,而是将值转换为其中一种类型。
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 to Entities不能识别方法'System.String ToString()'方法,而且这种方法不能被转换成存储表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文