This is my code:
private void loadList(IQueryable<customer> customers)
{
ListView.Items.Clear();
foreach (var customer in customers)
{
ListViewItem item = new ListViewItem(customer.customerNumber.ToString());
item.SubItems.Add(customer.customerName);
item.SubItems.Add(customer.contactFirstName);
item.SubItems.Add(customer.contactLastName);
item.SubItems.Add(customer.phone);
item.SubItems.Add(customer.addressLine1);
item.SubItems.Add(customer.addressLine2);
item.SubItems.Add(customer.city);
item.SubItems.Add(customer.state);
item.SubItems.Add(customer.postalCode);
item.SubItems.Add(customer.country);
item.SubItems.Add(customer.salesRepEmployeeNumber.ToString());
item.SubItems.Add(customer.creditLimit.ToString());
ListView.Items.AddRange(new ListViewItem[] { item });
}
}
private static readonly Func<customer, string>[] _searches;
static Main()
{
_searches = new Func<customer, string>[]
{
(c) => c.customerNumber.ToString(),
(c) => c.customerName,
(c) => c.contactFirstName,
(c) => c.contactLastName,
(c) => c.phone,
(c) => c.addressLine1,
(c) => c.addressLine2,
(c) => c.city,
(c) => c.state,
(c) => c.postalCode,
(c) => c.country,
(c) => c.salesRepEmployeeNumber.ToString(),
(c) => c.creditLimit.ToString(),
};
}
protected virtual void SearchBox_TextChanged(object sender, EventArgs e)
{
var search = _searches[SearchItem.SelectedIndex];
CustomerContext context = new CustomerContext();
IQueryable<customer> customers = from x in context.customers
where search(x).Contains(SearchBox.Text)
select x;
loadList(customers);
}
I am getting this error in the loadList
method at the start of the foreach:
'The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.'
How do I solve this? I am fairly new to all this and I've tried a couple things but none of them worked.