This is a migrated thread and some comments may be shown as answers.

Self-Referencing Hierarchy using LINQ and Nullable Guids

2 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sypher
Top achievements
Rank 1
Sypher asked on 20 Jan 2011, 08:29 PM
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 Answers, 1 is accepted

Sort by
0
Sypher
Top achievements
Rank 1
answered on 20 Jan 2011, 08:36 PM
Oh! If I set EnableLinqExpression = "false", I can use "ParentID IS NULL" and it seems to work!
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 03 May 2011, 10:32 PM
thanks sypher, it really helped me a LOT!

regards.
Tags
Grid
Asked by
Sypher
Top achievements
Rank 1
Answers by
Sypher
Top achievements
Rank 1
Silvio Silva Junior
Top achievements
Rank 2
Share this question
or