I created a ListViewModel something like this
public class ListPersonalsViewModel
{
public long PersonalID { get; set; }
public int NationalCode { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
and I use this code
public List<ListPersonalsViewModel> GetNamePersonal(string filter = "")
{
if (filter == null)
{
return db.tblPersonals.Select(p => new ListPersonalsViewModel()
{
NationalCode = p.NationalCode,
PersonalID = p.PersonalID,
FirstName = p.FirstName,
LastName = p.LastName
}).ToList();
}
return db.tblPersonals.Where(p => p.FirstName.Contains(filter)||
p.LastName.Contains(filter) ||
p.NationalCode.Contains(filter) ||
p.PersonalID.Contains(filter))
.Select(p => new ListPersonalsViewModel()
{
NationalCode = p.NationalCode,
PersonalID = p.PersonalID,
FirstName = p.FirstName,
LastName = p.LastName
}).ToList();
}
Now my question: how i can convert PersonalID
and NationalCode
to string for work here?
Here just 2 my string filter work
i receive this 2 error
Error CS1929 'long' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.
Error CS1929 'int' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.
i think this is better for understanding
with this code my problem solved
,,,
return db.tblPersonals.Where(p => p.FirstName.Contains(filter)||
p.LastName.Contains(filter) ||
p.NationalCode.ToString().Contains(filter) ||
p.PersonalID.ToString().Contains(filter))
.Select(p => new ListPersonalsViewModel()
,,,