CodeSmith Community
Your Code. Your Way. Faster!

New Query Builder Classes

Latest post 05-22-2008 10:30 AM by vbandrade. 44 replies.
  • 06-20-2007 10:00 AM In reply to

    Re: New Query Builder Classes

    Hi,

    I'm using the Petshop sample to try out the SqlStringBuilder and EntityStringBuilder classes, but I can't seem to get it working.

    My code is below:

    Petshop.AccountService accountService = new AccountService();
    TList<Account> AccountList = new TList<Account>();
    Petshop.Data.Bases.AccountFilterBuilder afb = new Petshop.Data.Bases.AccountFilterBuilder();
    afb.Append(
    AccountColumn.FirstName,"Kim%");
    AccountList = accountService.Find(afb.ToString());

    The call to afb.ToString() produces the following where clause:

    " (FirstName LIKE 'Kim%')"

    When passed to the Petshop.Entities.TList<Account> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count) method, the following exception is thrown:

    ArgumentException("Unable to use this part of the where clause in this version of Find: " + clause);

    I believe this is because of the leading open bracket "(" before the column name.

    Thanks,

    RK

     

    • Post Points: 35
  • 06-20-2007 10:07 AM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: New Query Builder Classes

    Try:

    AccountList = accountService.Find(afb.GetParameters());

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 06-20-2007 11:06 AM In reply to

    Re: New Query Builder Classes

    I don't see that method as part of the AccountFilterBuilder class. If I use the code given, I get the following error

    'Petshop.Data.Bases.AccountFilterBuilder' does not contain a definition for 'GetParameters'

    I am using .NetTiers v2.0.1.471

    Thanks,

    RK

     

    • Post Points: 35
  • 06-20-2007 12:09 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: New Query Builder Classes

    Sorry, use the AccountParameterBuilder class (which has the GetParameters method).

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 06-20-2007 12:53 PM In reply to

    Re: New Query Builder Classes

    Thanks. That worked!

    • Post Points: 5
  • 09-09-2007 11:35 PM In reply to

    • bhumkars
    • Not Ranked
    • Joined on 09-06-2007
    • Posts 1
    • Points 35

    Re: New Query Builder Classes

    Regarding "query2.Append(CustomersColumn.City, "London, Berlin");", which results in "(City = 'London' OR City = 'Berlin')"

    As per my experience, the IN clause works faster than list separated with OR condition. Therefore, how about creating IN clause whenever we get the list of comma delimited parameters. I will be doing in "IN Clause" way.

    Your opinion?
     

    • Post Points: 35
  • 09-10-2007 9:57 AM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: New Query Builder Classes

    Just use the AppendIn method, which will do what you are looking for...

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
  • 10-31-2007 11:17 PM In reply to

    Re: New Query Builder Classes

    how to keep the sorting functionality on EntityGridView working when using the builder with the TList?
    Always get the err messafe that the datasource doenst support sorting.

     

    THANKS. 

     

    OQ 

    • Post Points: 5
  • 01-23-2008 1:02 PM In reply to

    • lelong37
    • Not Ranked
    • Joined on 01-06-2008
    • Posts 2
    • Points 65

    Re: New Query Builder Classes

    When performing a Deepload is there anyway to specify a where clause for the native table the provider is for and also for a column in one of the tables that are joined in the DeepLoad?

    i.e: Performing a Deepload on Orders with tables: OrderDetails and ShippingMethod, and being able to specify a where clause or ParamenterBuilder on Orders with status = Open (clause for Order table), states = CA (clause for joined State table), ShippingMethod = Overnight (clause for joined Shipping table)?

    Thanks in advance,

     -Le

     BTW: Nettiers and Codesmith Rocks! Big Smile

    NetTiers Rocks...!
    Filed under: , , ,
    • Post Points: 5
  • 05-14-2008 6:53 AM In reply to

    Re: New Query Builder Classes

    Hello,

     you showed how to find in a view classe via ParameterBuilder.  Very useful descipted

     

    I got a view  View_EmployeeSkill.  Using View_EmployeeSkillParameterBuilder  I receive as Result a VList<View_EmployeeSkill> 

    How can I use that List for a second search step ?

     

    another point.

    .That project is planned for an WebService. Because of  the MVC princip there is an Seperation between GUI and business logic.

    For an intelligent business logic it would be nice, that name and value  of search parameter could only be interesting at runtime.

    as I have seen at the samples above, the columnname ist wanted. 

     

    very thanks

     

     

    • Post Points: 35
  • 05-17-2008 2:54 PM In reply to

    • lelong37
    • Not Ranked
    • Joined on 01-06-2008
    • Posts 2
    • Points 65

    Re: New Query Builder Classes

     Not sure if I understand the question correctly but to perform a search within your list heres how:


    // Finding one employee
    View_EmployeeSkill view_EmployeeSkill =
     VList<View_EmployeeSkill>.Find( View_EmployeeSkill.Column.EmployeeId, 18);

    // Finding one employee (delgation usage on two conditions)
    View_EmployeeSkill view_EmployeeSkill =
     VList<View_EmployeeSkill>.Find(
         delegate(View_EmployeeSkill.Column v) { return v.EmployeeId == 18 && v.DepartmentId = 25; } ) );

    // Finding employee set
    VList<View_EmployeeSkill> view_EmployeeSkills =
     VList<View_EmployeeSkill>.FindAll( View_EmployeeSkill.Column.DeptartmentId, 25);

    // Finding employee set (delgation on two conditions)
    VList<View_EmployeeSkill> view_EmployeeSkills =
     VList<View_EmployeeSkill>.FindAll( 
         delegate(View_EmployeeSkill.Column v) { return v.SkillType == 3 && v.DepartmentId = 25; } ) );

    NetTiers Rocks...!
    • Post Points: 60
  • 05-21-2008 3:08 AM In reply to

    Re: New Query Builder Classes

     Thanks for answering.

     I think I can handle your respond. 

     

     What I still haven't found: how to use ParameterBuilder.  Okay, I know how to build the ParameterBuilder string. 

    also to call the DB via the service .

     

    but the final:    find (...GetParameters())  How do I set the Parameters with  values? 

     should it be into the brackets ? --> GetParameters(...,...)

     

     

    • Post Points: 35
  • 05-21-2008 8:50 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 181
    • Points 4,520

    Re: New Query Builder Classes

    Check yyour answer here:

    http://community.codesmithtools.com/forums/t/8401.aspx 

    • Post Points: 5
  • 05-22-2008 9:13 AM In reply to

    Re: New Query Builder Classes

    That's my code for method.

     

    In my list I want to get something like Query.searchQuery.AppendGreaterThanOrEqual

     and it seems for me, writing a delegate is nessessary.

     

    the thick code line is the point, there I got my problems.  

    thanks 

     

     

    public int IterateFind(ref VList<View_EmployeeSkill> list, View_EmployeeSkillColumn column, string value)
            {
                View_EmployeeSkillFilterBuilder searchQuery = new View_EmployeeSkillFilterBuilder();

                if (column.Equals(View_EmployeeSkillColumn.SkillLevel))
                {
                    int number = -1;
                    int.TryParse(value,out number);

                    list = list.FindAll(delegate(list l) { return l.SkillLevel > number || l.SkillLevel == number; });
                    //list.FindAll(column >
                }
                else
                {
                    list = list.FindAll(column,value);
                    //searchQuery.Append(column, value);
                }


                return list.Count;
            }

    • Post Points: 35
  • 05-22-2008 10:30 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 181
    • Points 4,520

    Re: New Query Builder Classes

    It looks right, I would do it in a different way.

     

    * Theres no need to use the ref keyword, its a reference type already.
    * I would return the filtered list. That way i would end up with the original list and the new one.
    * Theres no need to return the list count. Returning the filtered list, haven both lists you can compare and do more stuf.
    * Your predicate could have just one test.

     So, with my changes, I end up with this:

     

    public VList<View_EmployeeSkill> IterateFind(VList<View_EmployeeSkill> list, View_EmployeeSkillColumn column, string value)
            {
                if (column.Equals(View_EmployeeSkillColumn.SkillLevel))
                {
                    int number = -1;
                    int.TryParse(value, out number);

                    return list.FindAll(delegate(View_EmployeeSkill vES) { return vES.SkillLevel >= number; });
                }
                else
                {
                    return list.FindAll(column, value);
                    //searchQuery.Append(column, value);
                }
            }

     

    If you want  do more stuff within the method with the result list just declare the variable and do your thing.

     

    Hope this helps. 

    • Post Points: 5
Page 3 of 3 (45 items) < Previous 1 2 3 | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems