mig_08
mig_08

Reputation: 181

linq like on relational data

I am trying to do a like on a table that has a one to many relationship with another. Having some issues with the code for that. Promotion table has a one to many relationship with PromotionMajorChains. I am trying to do a like on the PromotionMajorChains table, on the column MajorChain. The error I am getting: CS1503 Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'

Code:

case MAJOR_CHAIN:
         paginatedQueryable = paginatedQueryable.Where(e => EF.Functions.Like(e.Promotion.PromotionMajorChains.Select(mc => mc.MajorChain), $"%{filter.Value}%"));
         break;

Example filter.Value = "group"

Upvotes: 0

Views: 51

Answers (1)

Svyatoslav Danyliv
Svyatoslav Danyliv

Reputation: 27416

If you have a set of records, apply predicates which are dedicated for that

paginatedQueryable = paginatedQueryable
   .Where(e => e.Promotion.PromotionMajorChains.Any(mc =>
      EF.Functions.Like(mc.MajorChain, $"%{filter.Value}%")
   );

Upvotes: 1

Related Questions