Closed twobytescy closed 4 years ago
Thank you so much @twobytescy I'm pushing this to NuGet as we speak as version 3.0.1. Cheers, Joel
Hi @twobytescy in doing some testing I'm running into cases where the correct Expression constructor isn't being used. I'm going to merge the explicit 'Between' constructor into the normal constructor and re-work this a bit. Stay tuned.
This seems to work:
List<string> returnFields = new List<string> { "firstName", "lastName", "age" };
List<object> vals = new List<object>();
vals.Add(10);
vals.Add(20);
Expression e = new Expression("id", Operators.Between, vals);
Console.WriteLine("Expression: " + e.ToString());
_Database.Select("person", null, null, returnFields, e, "ORDER BY age DESC");
But this gets pulled into the regular public Expression(object left, Operators oper, object right)
constructor instead of the desired public Expression(object left, Operators oper, List<object> right)
constructor:
List<string> returnFields = new List<string> { "firstName", "lastName", "age" };
Expression e = new Expression("id", Operators.Between, new List<int> { 10, 20 });
Console.WriteLine("Expression: " + e.ToString());
_Database.Select("person", null, null, returnFields, e, "ORDER BY age DESC");
So we may be stuck with the caller explicitly using List<object>
even though they may want to use int
, decimal
, string
, etc...
https://stackoverflow.com/questions/62184219/multiple-constructors-using-generics-and-lists
Will watch this and see if there is a better solution, but for now, I think the one you've created is the most appropriate. Caveat being the caller has to explicitly use List<object>
, but it works great when that's what they use.
Cheers, Joel
Hi @twobytescy given the confusion a consumer of the library may encounter when trying to do Between
, would you be opposed to me creating a static factory for this?
i.e.
public static Expression Between(object left, List<object> right)
{
...
}
This would keep people from tripping over the issue of their Expressions not being built correctly because they use strongly-typed List<> instead of List
Let me know what you think. Thanks! ~Joel
Hello.
Well this was my initial implementation and I had it changed to be consistent with your other constructors.
I totally agree with you
S
On Thu, 4 Jun 2020 at 6:55 AM, Joel Christner notifications@github.com wrote:
Hi @twobytescy https://github.com/twobytescy given the confusion a consumer of the library may encounter when trying to do Between, would you be opposed to me creating a static factory for this?
i.e.
public static Expression Between(object left, List
This would keep people from tripping over the issue of their Expressions not being built correctly because they use strongly-typed List<> instead of List for the right term.
Let me know what you think. Thanks! ~Joel
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jchristn/DatabaseWrapper/pull/2#issuecomment-638587271, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL6JJMX6JSBL7TPUNGD622LRU4LMRANCNFSM4NPRPJDA .
My apologies @twobytescy i will get this changed and fixed on my end. Thanks!
Utilizing GreaterThanOrEqualTo and LessThanOrEqualTo operators