Joker
Joker

Reputation: 830

C# Predicate builder with multiple Tables

I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, InvoiceNo, RevisionNo. A Receipt can have multiple Invoices. So in my receipts listing page there is a column called InvoiceSet which will display a list of (InvoiceNo + RevisionNo) in a comma separated manner

Eg : 2000155 A, 200111 B

in a single column. I have a search field on top of my list page where a User can search the entire list using key words. For that purpose i am using predicatebuilder. So when a user searches 200111 B the list should filter and show the row which has the given search key. Since the given search key is a combination of invoiceNo and RevisionNo (200111 = invoiceno, B = RevisionNo) from Invoice table i am not able to build a predicate that can combine the two columns using predicatebuilder.

I tried like this :

p.Receipts.Any(a =>  a.Invoice.InvoiceNo + " " + a.Invoice.RevisionNo).Contains(criteria.Search.Value)

but it's giving me error stating

Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type

Both the InvoiceNo and RevisinNo is of type string

Is it possible with predicatebuilder to acheive what i am looking for ?

Upvotes: 0

Views: 515

Answers (1)

Danko Durbić
Danko Durbić

Reputation: 7247

Should it be:

p.Receipts.Any(a => (a.Invoice.InvoiceNo + " " + a.Invoice.RevisionNo).Contains(criteria.Search.Value))

Upvotes: 0

Related Questions