我正在尝试编写一个我将使用 ajax 调用的 Linq 方法。我有以下错误我不知道如何解决?
无法将类型 'System.Collections.Generic.List<ChillZARdev.Contents.DesignProfile.SearchResults>' 隐式转换为 'System.Collections.Generic.List<string>' D:\LetsWork0\ChillZARdev\ChillZARdev\Contents\Home.aspx。 CS
错误突出显示在 return lsSearchResults;
public static List<SearchResults> lsSearchResults = new List<SearchResults>();
public static DBRelationalDataContext myDB = new DBRelationalDataContext(); public class SearchResults
{
public string Name { get; set; }
public string Surname { get; set; }
public SearchResults(string name, string surname)
{
Name = name;
Surname = surname;
}
}
[WebMethod]
Public static List<string> QuerySearch()
{
var found = (from User in myDB.Memberships
where User.Name.ToLower().Contains(RecordSearch) ||
User.Surname.ToLower().Contains(RecordSearch) ||
(User.Name + " " + User.Surname).ToLower().Contains(RecordSearch) ||
(User.Surname + " " + User.Surname).ToLower().Contains(RecordSearch)
select new SearchResults(User.Name, User.Surname)).ToList();
//// validates items in search query if Exist
if (!ChillZARdev.App_Code.Utilities.IsEmpty(found))
{
// List<string> userRecord = new List<string>();
List<SearchResults> lsSearchResults = new List<SearchResults>();
foreach (var user in found)
{
// userRecord.Add(user.Name );
lsSearchResults.Add(new SearchResults(user.Name, user.Surname));
}
//Repeater1.EnableViewState = true;
return lsSearchResults; // This is where the errror is highlighted
}
}