This should work
houses.AsQueryable<House>().Where(rs=>rs.MainRoom.Type == RoomType.Kitchen);
Why do you need dynamic linq in this case? What result do you expect
To my preference, the use of an error string should be avoided. If your class or property name has changed, you cannot find the error until you encounter it.
Use expression rather
Expression<Func<House, bool>> filter = (p) => p.MainRoom.Type == RoomType.Kitchen; filter = (p) => p.MainRoom.Area > 200; filter = (p) => p.Rooms.Sum(rs => rs.Area) > 500; filter = (p) => p.Address.Contains("abc"); filter = (p) => p.Area > 200; ... var aRoomsHouses = houses.AsQueryable<House>().Where(filter);
You can create an expression in which you decide which string filter to use. It's better to create a static class, or maybe a switch statement that gives you a different type of expression that you can use as the where argument.
source share