In part I I took a look at a basic implementation of a dynamic find by method. Tony Nelson was quick to point out that this would not work if you had entity names that contained AND such as Candidate. I went back to the drawing bored and with a nice idea from Tony I cam up with another solution. His example was a little more dynamic ubt please understand this is a stand alone example for a reason. This functionality is going to be created in my abstract service layer. Anything that is going to be common among all service objects should not be repeated.

So how are we going to fix this problem with the AND keyword. The AND join is going to tell us that we need to find rows by 2 different fields. This could be improved upon to handle many ands but I really don't see myself ever needing more than 2 lookups for a find by method. If we know what entity we are working with we can do a lookup for the properties of that entity. In the hard coded example case we know we are working with the Art entity so we can do the following. Given the fact that we know the valid properties of the entity we can do the following.

  1. Does any part of the missing method name after findby contain AND
  2. If no - then just return that as the lone field
  3. If yes - are the left and right sides of and valid properties? If so we have a join. If not we have a field name.

Remember this whole time we have been working with the dynamic find by method. The find by method is looking for exact methods. If we wanted to we could use this same logic for a search by method. These and many more methods are going to provide a constant API for talking with Entities. I will be posting my abstract service layer shortly so stay tuned. Until then here is the stand alone service component.