The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Retrieving the value of a property at runtime

Last post 07-15-2008, 3:10 PM by Morak. 7 replies.
Sort Posts: Previous Next
  •  07-14-2008, 12:43 PM 10243

    Retrieving the value of a property at runtime

    I have collection bound to a checkedListBox in a winform and need the values of each checked item.  The catch is that at runtime I do not know the property.

     

    The list box populates as expected using the following code:

     

    private void populateList(string feildName)

            {

                VwSelectionDataCollection coll = new VwSelectionDataCollection();

                List<string> myList = new List<string>();

                myList.Add(feildName);

                coll.Query.Select(myList.ToArray());

                coll.Query.GroupBy(myList.ToArray());

                coll.Query.Load();

     

                lstSelectionValues.DataSource = coll;

                lstSelectionValues.ValueMember = feildName;

                lstSelectionValues.DisplayMember = feildName;

            }

     

    On selection of an Item in the checkbox I am attempting to populate a list of values selected.

     

    private void lstSelectionValues_SelectedIndexChanged(object sender, EventArgs e)

            {

                string myValue = "";

               

               

                foreach (VwSelectionData myRow in lstSelectionValues.CheckedItems)

                {

                             if (i > 0)

                               myValue += ",";

                   

     myValue +=  

     

    // This code works if the fieldname is Category but I need to pass the property name at runtime.

                             //myValue += myRow.Category.ToString();

                }

                grdCriteria.CurrentRow.Cells[2].Value = myValue;

            }

     

     

    This code can provide the property name but I’m not sure how to wire it up to provide the value of the property.

    myRow.Collection.es.Meta.Columns.FindByColumnName("Category ").PropertyName.ToString();

     

    Jeff

  •  07-14-2008, 1:10 PM 10244 in reply to 10243

    Re: Retrieving the value of a property at runtime

    Hi Jeff

    The method you're looking for is "GetColumn(propertyname)" - that should get you sorted

    Cheers

    Martin

  •  07-14-2008, 2:16 PM 10245 in reply to 10244

    Re: Retrieving the value of a property at runtime

    Thanks again Martin, it worked like a charm.  On a related note I’m having an issue with the in() function.  I’m using the grid you were working on that build a query at runtime but I’m populating the parameters field using list box.  If the in operator is selected I populate the parameters filed with values separating with a comma but it only works if I pass in one value.  Do you have any thoughts?

     

    Jeff

  •  07-15-2008, 12:14 AM 10246 in reply to 10245

    Re: Retrieving the value of a property at runtime

    Hi Jeff

    I've not had a chance to look at the query builder for a while but I know that you can use an array for the In() clause so why not build an array (of the appropriate type) from the selections in the listbox and pass that array in as your param?

    Cheers

    Martin

  •  07-15-2008, 10:05 AM 10250 in reply to 10246

    Re: Retrieving the value of a property at runtime

    My goal is to have the list box populated with the values based on the field selected in the grid. The user can select item in the list box and the parameters field would be populated for each item selected. However the user should still be able to hand type in a parameter.

     

    I have not tested the selection grid for all SQL operators but IN() operator appears to only work if there is one value.  I have tried the separating the values with spaces, quotes, single quotes, commas as well all combination.  I’ll give the array a shot, but does that mean that the selection grids In() and NotIN() function is broken? 

     

    I was hoping I was just using the delimiter J

     

    Jeff

  •  07-15-2008, 10:34 AM 10251 in reply to 10250

    Re: Retrieving the value of a property at runtime

    Hi Jeff

    Don't forget that the "selection grid" was more of an experiment/proof of concept from my side (not EntitySpaces) and as such it's a) not finished (barely started if I'm honest), b) not "supported" (although I'll help where I can) and c) not broke - if it ain't finished, it ain't broke Big Smile

    From my perspective the grid was only slapped together (literally!) so that I could have an attempt at creating a query on the fly based on user input - if I'm honest I don't think that a grid is the best input mechanism for a query builder as the number of params needed based on the different query operators ranges from zero (Not Null/Is Null etc) through to lots (limited only by your DB) so as I say, the grid idea was more of a mock-up/starting point rather than an end-point for me if that makes sense - I've been thinking of having some sort of "panel" control for this but have had absolutely zero spare time to look at it I'm afraid.

    Try the array though - it may well work (haven't tried it though I'm afraid)

    Cheers

    Martin

  •  07-15-2008, 11:15 AM 10252 in reply to 10250

    Re: Retrieving the value of a property at runtime

    The signature for EntitySpaces In() and NotIn() is (params Object[] value). If you pass it a delimited string, EntitySpaces considers that one value. Here are a couple of our NUnit tests which should give you some direction. These tests pass for all our providers. EntitySpaces takes the values, adds provider specific delimiters where necessary, and creates the comma separated list for you. You can confirm what is sent to the server with LastQuery.

    Code:
    public void WhereInListText()
    {
        ArrayList array = new ArrayList();
        array.Add("Test");
        array.Add("Test2");
    
        ArrayList anotherArray = new ArrayList();
        anotherArray.Add("Foo");
        anotherArray.Add("Four");
    
        List<string> generic = new List<string>();
        generic.Add("Seven");
        generic.Add("Vincent");
    
        aggTestColl.Query.Where(
            aggTestColl.Query.LastName.In(
                "Doe", array, "foo", anotherArray, generic));
        Assert.IsTrue(aggTestColl.Query.Load());
        Assert.AreEqual(5, aggTestColl.Count);
    }
    
    public void WhereInListNumeric()
    {
        ArrayList array = new ArrayList();
        array.Add(1);
        array.Add(2);
    
        ArrayList anotherArray = new ArrayList();
        anotherArray.Add(3);
        anotherArray.Add(25.03);
    
        List<int> generic = new List<int>();
        generic.Add(5);
        generic.Add(6);
    
        aggTestColl.Query.Where(
            aggTestColl.Query.Salary.In(
                7, array, 11.06, anotherArray, generic));
        Assert.IsTrue(aggTestColl.Query.Load());
        Assert.AreEqual(2, aggTestColl.Count);
    }

    David Neal Parsons
    www.entityspaces.net
  •  07-15-2008, 3:10 PM 10253 in reply to 10251

    Re: Retrieving the value of a property at runtime

    Martin I think the your grid is brilliant for demonstrating an state forward way for end users to created a query using entity spaces.  I’m expanding for a project at work and using it to learn so thanks for the staring point and to quick tips.  I made the following modifications to your code to facilitate the In() NotIn() operators.

     

            string sqlOperator = c.Cells[1].Value.ToString();

                        if (sqlOperator.EndsWith("In"))

                        {

                            object[] split = args[0].ToString().Split(',');

                            query.Where(DynaInvoke.InvokeMethod(qi, sqlOperator, split));                 

                        }

                        else

                        {

                            query.Where(DynaInvoke.InvokeMethod(qi, sqlOperator, args));

                        }

    Jeff

View as RSS news feed in XML