Operator '==' cannot be applied to operands of type 'int' and 'string'

.net, c#, linq

Solution

You need to convert `selectedDepartment` to integer before comparing it in the LINQ query.

int selectedDepartment = Convert.ToInt32(rcbDepartment.SelectedValue);

In your query:

ctx.HtDepartments.SingleOrDefault(d => d.DepartmentId == selectedDepartment);

`d.DepartmentId` is of type int whereas `selectedDepartment` is a string and you can compare both using `==` operator.

Problem

I have a little misunderstanding here why do i have here an error do i need to parse it what is wrong with this code ? ``` UberTrackerEntities ctx = UberFactory.Context; IEnumerable<HtUser> users = HtUser.GetAll(); string selectedBU = rcbBusinessUnits.SelectedValue; string selectedDepartment = rcbDepartment.SelectedValue; HtDepartment department = ctx.HtDepartments.SingleOrDefault(d => d.DepartmentId ==selectedDepartment); if (department != null) { users = users.Where(u => u.HtDepartments.Contains(department)); } ``` Thanks for help and fast answer ! PS:I thing I'm just over thing it it seams just to be a stupid little error ...

Original source