Self-Referencing Hierarchy using LINQ and Nullable Guids

3 posts, 0 answers
  1. Sypher
    Sypher avatar
    79 posts
    Member since:
    Aug 2006

    Posted 20 Jan 2011 Link to this post

    Following the help from http://www.telerik.com/help/aspnet-ajax/grdselfreferencinghierarchy.html, I cannot seem to find a FilterExpression that works with my data source.  I am using the NeedDataSource event to set the data source like this:

    dcConnections dc = new dcConnections();
    g.DataSource = dc.GetMetrics();

    dcConnections is my DataContext, GetMetrics is a stored procedure that returns a list of Metrics.  The Metrics have an ID and ParentID, both of which are Guids.  ParentID can be null.  So, from the example, I tried to set the FilterExpression like this:

    if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1 || Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("4.0") != 1)
    {
        g.MasterTableView.FilterExpression = @"it[""ParentID""] == null";
    }
    else
    {
        g.MasterTableView.FilterExpression = "ParentID IS NULL";
         
    }

    This errors out with "No applicable indexer exists in type 'Metric'", which makes sense, since I need to use the it.ParentID format to get to the column in the Metric normally, so I change it to this:

    g.MasterTableView.FilterExpression = @"it.ParentID == null";

    That errors with "Operator '==' incompatible with operand types 'Guid?' and 'Object'".

    So now, I can't figure out how to compare the values of a Guid? in a FilterExpression.  Normally, using == null would work for Nullable Guids.  Any suggestions?
  2. Sypher
    Sypher avatar
    79 posts
    Member since:
    Aug 2006

    Posted 20 Jan 2011 Link to this post

    Oh! If I set EnableLinqExpression = "false", I can use "ParentID IS NULL" and it seems to work!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Silvio Silva Junior
    Silvio Silva Junior avatar
    100 posts
    Member since:
    Mar 2010

    Posted 03 May 2011 Link to this post

    thanks sypher, it really helped me a LOT!

    regards.
Back to Top