How to compare strings matching using Linq?

I’m trying to implement an interface in Notification repository:

IEnumerable<Notification> INotificationRepository.GetAllNotificationById(int userId)
            return context.Notifications.Where(x => x.receiverUserId.Split(',').Contains(userId.ToString())).ToList();

IDE shows error under x.receiverUserId.Split(',') and says:

an expression tree may not contain a call or invocation that uses
optional arguments.

How can I fix it?

>Solution :

Add a value to the optional StringSplitOptions argument:

...context.Notifications.Where(x => x.receiverUserId.Split(',', StringSplitOptions.None)...

Leave a Reply