下午全部 - 这是星期五的13日,所以当然我有一个绝对的母马!!!
下面的代码,“应该”创建将在文本框自动填充中使用的项目列表。
public string[] GetAutoComplete(string prefixText, int count)
{
try
{
string memberid = HttpContext.Current.Session["VDS_MemberID"].ToString();
string locationid = HttpContext.Current.Session["VDS_LocationID"].ToString();
string inhouse = HttpContext.Current.Session["VDS_Inhouse"].ToString();
string supplier = HttpContext.Current.Session["VDS_Supplier"].ToString();
string groupw = HttpContext.Current.Session["VDS_Group"].ToString();
string external = HttpContext.Current.Session["VDS_External"].ToString();
VDSORDAL.PDC_VDSOREntities autocomplete = new VDSORDAL.PDC_VDSOREntities();
var r = (from p in autocomplete.tblAutoCompletes
where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
select p);
if (inhouse != "DoNotDisplayInhouse")
r = r.Where(p => p.ACItem == inhouse);
if (supplier != "DoNotDisplaySupplier")
r = r.Where(p => p.ACItem == supplier);
if (groupw != "DoNotDisplayGroup")
r = r.Where(p => p.ACItem == groupw);
if (external != "DoNotDisplayExternal")
r = r.Where(p => p.ACItem == external);
return r.Distinct().OrderBy(p => p.ACItem).ToString();
}
但是,我将问题标题视为错误。
有人可以建议解决这个问题吗?道歉......我今天过得很糟糕。
答案 0 :(得分:1)
可能
return r.Distinct().OrderBy(p => p.ACItem).ToString();
应该是
return r.Distinct().OrderBy(p => p.ACItem).ToArray();
更新:
听起来这是你真正的问题。尝试(以下代码是脑编译的)
return (from p in r orderby p.ACItem desc select p.ACItem).ToArray();
我假设ACItem
是您想要返回的字符串,如果没有,请在数组中选择您想要的字符。
或者可能
return (from p in r where p != null orderby p.ACItem desc select p.ACItem).ToArray();
where p != null
可能是必要的,你几乎需要检查r,看看那里有什么,没有足够的信息能够最终回答这个问题。
也就是说,.ToArray
代替.ToString
仍然是您问题的答案,其他任何问题都是不同的问题。
答案 1 :(得分:1)
最后一行应该是:
return r.Distinct().OrderBy(p => p.ACItem).ToArray();
答案 2 :(得分:0)
不要做ToString()
。使用ToArray()
或ConvertAll<string>().ToArray()