Problem in GetScalar()

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 19-May-2009 07:19:51   

i have following code


            string PageName = Request.QueryString["txtPageName"].ToString();
            IPredicateExpression filter = new PredicateExpression();
            filter.Add(CmsContentDetailsFields.TxtPageName == PageName);
            CmsContentDetailsCollection col = new CmsContentDetailsCollection();
            int id = (int)col.GetScalar(CmsContentDetailsFieldIndex.IntNodeId, null, null, filter);

it gives following errors

Error 21 The best overloaded method match for 'Rigelnetworks.CollectionClasses.CmsContentDetailsCollection.GetScalar(Rigelnetworks.CmsContentDetailsFieldIndex, SD.LLBLGen.Pro.ORMSupportClasses.IExpression, SD.LLBLGen.Pro.ORMSupportClasses.AggregateFunction, SD.LLBLGen.Pro.ORMSupportClasses.IPredicate)' has some invalid arguments D:\Working Projects\05_05_2009_CMS_Web\SubMenuLeftSide.ascx.cs 30 27 D:\Working Projects\05_05_2009_CMS_Web\

Error 22 Argument '3': cannot convert from '<null>' to 'SD.LLBLGen.Pro.ORMSupportClasses.AggregateFunction' D:\Working Projects\05_05_2009_CMS_Web\SubMenuLeftSide.ascx.cs 30 86 D:\Working Projects\05_05_2009_CMS_Web\

Please help me out.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-May-2009 08:07:38   

You should spesify an Aggregate function for the GetScalar method. Use the following overload:

so either use the following:

int id = (int)col.GetScalar(CmsContentDetailsFieldIndex.IntNodeId, null, AggregateFunction.None, filter);

or

int id = (int)col.GetScalar(CmsContentDetailsFieldIndex.IntNodeId, null, AggregateFunction.Max, filter);

If you are sure the filter will only return one value, then using Max, Min or Avg won't hurt.

Posts: 97
Joined: 29-Apr-2009
# Posted on: 19-May-2009 09:04:27   

Walaa wrote:

You should spesify an Aggregate function for the GetScalar method. Use the following overload:

so either use the following:

int id = (int)col.GetScalar(CmsContentDetailsFieldIndex.IntNodeId, null, AggregateFunction.None, filter);

or

int id = (int)col.GetScalar(CmsContentDetailsFieldIndex.IntNodeId, null, AggregateFunction.Max, filter);

If you are sure the filter will only return one value, then using Max, Min or Avg won't hurt.

thanks walaa.