Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I fix it?

>Solution :

Add a value to the optional StringSplitOptions argument:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading