GithubHelp home page GithubHelp logo

repowrapper's People

Contributors

bbraithwaite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

repowrapper's Issues

About Pushing it to wild world

I used your DynamicQery generator in real life scenario. I made couple changes. Are you planning to make it ready for real life scenario?

Query builder should use item value

I found another problem, you're using item.QueryOperator instead of property value, as shown below:

if (!string.IsNullOrEmpty(item.LinkingOperator) && i > 0)
{
builder.Append(string.Format("{0} {1} {2} @{1} ", item.LinkingOperator, item.PropertyName,
item.QueryOperator));
}
else
{
builder.Append(string.Format("{0} {1} @{0} ", item.PropertyName, item.QueryOperator));
}

I already fixed it, you can use the code below:

for (int i = 0; i < queryProperties.Count(); i++)
{
QueryParameter item = queryProperties[i];

            if (!string.IsNullOrEmpty(item.LinkingOperator) && i > 0)
                builder.Append($"{item.LinkingOperator} {item.FieldName} {item.QueryOperator} {item.Value} ");
            else
                builder.Append($"{item.FieldName} {item.QueryOperator} {item.Value} ");

            expandoObj[item.FieldName] = item.Value;
        }

Not able to retrieve value from BinaryExpression.Right

I was trying to use the WalkTree method, but it was getting an error: propertyValue.Value is not defined.

I already fixed it. I just built a new method to retrive the value from a BinaryExpression:

private static void WalkTree(BinaryExpression body, ExpressionType linkingType, ref List queryProperties)
{
if (body.NodeType != ExpressionType.AndAlso &&
body.NodeType != ExpressionType.OrElse)
{
string propertyName = GetPropertyName(body);
dynamic propertyValue = GetValue(body);
string opr = GetOperator(body.NodeType);
string link = GetOperator(linkingType);

            queryProperties.Add(new QueryParameter(link, propertyName, propertyValue, opr));
        }
        else
        {
            WalkTree((BinaryExpression)body.Left, body.NodeType, ref queryProperties);
            WalkTree((BinaryExpression)body.Right, body.NodeType, ref queryProperties);
        }
    }

    private static object GetValue(BinaryExpression func)
    {
        return Expression.Lambda(func.Right).Compile().DynamicInvoke();
    }

Btw, very nice implementation ๐Ÿ‘

Doesn't work with NULLs in SQL

It translates NULLs into = null as if it were any other value, which doesn't return anything from your query because SQL doesn't properly understand = null.

I fixed this by putting in a check, if the value is null and the operator is = then append IS NULL, and don't add it as a parameter. The same for != too.

Unoptimised/unrefactored code:

if (!string.IsNullOrEmpty(item.LinkingOperator) && i > 0)
{
    if (item.PropertyValue == null && item.QueryOperator == "=")
    {
        builder.Append(string.Format("{0} {1} IS NULL", item.LinkingOperator, item.PropertyName));
    }
    else if (item.PropertyValue == null && item.QueryOperator == "!=")
    {
        builder.Append(string.Format("{0} {1} IS NOT NULL", item.LinkingOperator, item.PropertyName));
    }
    else
    {
        builder.Append(string.Format("{0} {1} {2} @{1} ", item.LinkingOperator, item.PropertyName,
                                     item.QueryOperator));
    }
}
else
{
    if (item.PropertyValue == null && item.QueryOperator == "=")
    {
        builder.Append(string.Format("{0} IS NULL", item.PropertyName));
    }
    else if (item.PropertyValue == null && item.QueryOperator == "!=")
    {
        builder.Append(string.Format("{0} IS NOT NULL", item.PropertyName));
    }
    else
    {
        builder.Append(string.Format("{0} {1} @{0} ", item.PropertyName, item.QueryOperator));
    }
}

Output if you do x.Where(c => c.Someprop == 5 && c.AnotherProp != null) is then SELECT * FROM SOMETABLE WHERE Someprop = 5 && AnotherProp IS NOT NULL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.