Dordanov wrote:
However we now have run into a minor disadvantage of the generated code. We have a Users table with Users wich have a unique ID, a name, password, and a relation to a group.
Let's say we want to fetch a user by it's name (for login purposes) now we have to write the following code to achieve this:
IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(UserFieldIndex.Name, ComparisonOperator.Equal, "name"));
UserCollection users = new UserCollection();
users.GetMulti(filter);
However, this seems to me a bit much code for such a simple task. Before we started with llblgen, we tested another OR mapper (RapTier for those who are curious) where we edited the template to make Get methods for each column so we could use this:
User[] users = UserCollection.GetByName("name");
Wich is alot faster and less coding work (as programmers are lazy by nature )
Is there a reason it's not implemented this simple yet? and if not, will it be implemented in the near future?
We would love to see filtering like this implemented.
I don't think it will, for the following reason . If you have 100 tables in your project (and a lot have even more) and per table you have an average of 10 fields, you end up with 1000 GetBy... methods, of which a lot will never be used, because it makes more sense to query on 2 fields, or with another operator, or you want sorting, or limit the amount of rows returned.
If you want such a routine, create a utility class, for example for customer, and add the following routine:
public CustomerCollection GetByField(CustomerFieldIndex index, object value)
{
IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(index, ComparisonOperator.Equal, value));
CustomerCollection toReturn = new CustomerCollection();
toReturn.GetMulti(filter);
return toReturn;
}
But, perhaps you want sorting, limiting, relations etc. as well... then the GetByField is pretty limited.