adding an expression as a predicate

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Jan-2008 15:35:23   

Hello

I am sorry if this has been asked before, but I can't seem to find any reference to it. I have an xml column in my db table and I want to return all rows where a particular node exists in the xml column. I have managed to return the value true or false for the query in my datatable by doing as follows (taken from a previous thread one of my collegeus wrote)


 string xquery = "//part[@name=\"" + partName.ToLower() + "\"]";
            ResultsetFields fields = new ResultsetFields(3);

            fields.DefineField(PricePartFields.PricePartId, 0);
            fields.DefineField(PricePartFields.Name, 1);
            fields.DefineField(PricePartFields.PricePartQuery, 2);
            
            XQueryExpression expression = new XQueryExpression(PricePartFields.PricePartQuery, xquery,XQueryExpression.QueryMethods.Exist);
        
            fields[2].SetExpression(expression);

            DataTable dynamicList = new DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchTypedList(fields,
                                       dynamicList,
                                       bucket, 0,
                                       null, true, null);
            }
            return dynamicList;

This produces a query something like this:

SELECT [dbo].[PricePart].[PricePartId], [dbo].[PricePart].[Name], PricePartQuery.exist('//part[@name="markup"]') AS [PricePartQuery] FROM [dbo].[PricePart]

Now I want to run a very similar query, but I need to have a where clause that reads

Where PricePartQuery.exist('//part[@name="markup"]') =1

Do you have suggestions as to how I would accomplish this?

Thanks

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Jan-2008 15:56:13   

Using your code just use fields[2] in a predicate as follows:

PredicateExpression filter = new PredicateExpression(fields[2] == 1);
bucket.PredicateExpression.Add(filter);
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Jan-2008 16:08:37   

Hello!

Thanks for your fast reply.. I have tried this and it doesnt like it.. It tells me I "cannot apply "==" to operands of type IEntityField2 and int".

I am using the adapter model if that makes a difference.

Thanks

Bex

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Jan-2008 16:28:55   

Wuhooooo... got it to work..!!

All I needed was to cast it... so it was..:


bucket.PredicateExpression.Add((EntityField2)fields[2] == 1);

Thanks you so much for pointing me in the right direction..! I'm still getting used to LLBL.. but I do like it smile