嗨,谢谢你,
我有几个改变我的gridview的函数。因此,要了解当前视图中的内容,我希望跟踪ID。目前的代码如下:
public void getCurrent_GridView()
{
if (GridViewFacility.DataKeys.Count > 0)
{
WISSModel.WISSEntities context = new WISSModel.WISSEntities();
//Prepare to build a "Base" query:
IQueryable<WISSModel.Base> searchListQuery = context.Bases;
for (int i = 0; i < GridViewFacility.Rows.Count; i++)
{
String id = GridViewFacility.DataKeys[i].Value.ToString();
//Refine query, one search term at a time
searchListQuery =
searchListQuery.Where(p => p.isDeleted == false && (p.BaseId.ToString().Contains(id)));
//txtSearch.Text += id + " ";
}
txtSearch.Text = "test" + searchListQuery.ToList().Count;
GridViewFacility.DataSource = searchListQuery.ToList();
GridViewFacility.DataBind();
}
}
protected void GridViewFacility_RowEditing(object sender, GridViewEditEventArgs e)
{
getCurrent_GridView();
GridViewFacility.EditIndex = e.NewEditIndex;
LoadData();
}
在VS2013中,我收到此错误:
类型&#39; System.NotSupportedException&#39;的例外情况发生在 System.Data.Entity.dll但未在用户代码中处理
其他信息:LINQ to Entities无法识别该方法 &#39; System.String ToString()&#39;方法,这个方法不能 翻译成商店表达。
答案 0 :(得分:0)
嗯,信息很清楚,你不能使用.ToString()
在linq to entities中,您可以使用SqlFunctions.StringConvert
...将某些数值转换为字符串。它只适用于decimal和double,但您可以将int转换为double。
我猜您的错误就行了
p.BaseId.ToString().Contains(id)
如果BaseId
是int,则可以用
SqlFunctions.StringConvert((double)p.BaseId).Contains(id)