Blumonde

Blumonde

  • NA
  • 78
  • 28.9k

How to write a LinQ select statement with Contains string

Jul 7 2017 11:34 AM

Hello LinQ experts,


I have a problem with the query(in cap) below. It should be straightforward and simple but for some reason, it doesn't return the correct results. Please see below:


------------------------------------------------------------------

AdminConnection db2 = new AdminConnection();


IQueryable<MvcMenu> getMenu = db2.MvcMenu; // get all records from sql table


IEnumerable<MvcMenu> menusList = null;


if (User.IsInRole("Administrator"))
{
menusList = getMenu.OrderBy(i => i.Id).ThenBy(l => l.Level).ThenBy(p => p.Position).ToList(); // this query works fine.
}
else
{
menusList = getMenu.OrderBy(i => i.Id).ThenBy(l => l.Level).ThenBy(p => p.Position).Where(m => !m.GroupPermission.Contains("GroupAdmin") && !m.Permission.Contains("Administrator")).ToList(); // THIS QUERY DOESN'T WORK. It only returns 1 record when it should returns at least 3 records based on the current data.
}

---------------------------------------------------------


Would someone please tell me what am I missing here? My LinQ query above is incorrect? Please point me in the right direction.


Thank you.


Answers (2)