I'm trying to implement a search filter using LINQ in my ASP.Net application.
However I'm running into problems. Here is my code:
var result = (from x in db.ContactSet
select new Models.Contact
{
AccountId = x.AccountId,
FirstName = x.FirstName,
LastName = x.LastName,
FullName = x.FullName,
JobTitle = x.JobTitle,
ParentCustomerId = x.ParentCustomerId,
EMailAddress1 = x.EMailAddress1,
Telephone1 = x.Telephone1,
MobilePhone = x.MobilePhone,
Fax = x.Fax,
GenderCode = x.GenderCode,
BirthDate = x.BirthDate
}); //? Gets all rows
result = result
.Where(x =>
x.FirstName.Contains(model.searchPhrase) ||
x.LastName.Contains(model.searchPhrase)); //? Search Filter
The Gets all rows
code works perfectly in getting all the rows from my database. However I'm having issues with the Search Filter
part of the code.
model.searchPhrase
is a null-able string.
Every time I run through the Search Filter
nothing gets returned (doesn't matter what the input is.
After debugging I noticed that after that block of code runs I get the following Exception Error
:
Static members: 'NotSupportedException' is a type, which is not valid in the given context. Non-public members: 'new System.Linq.SystemCore_EnumerableDebugView(result).items' thew an exception of type 'System.NotSupportedException'
Any idea what's wrong here?