views:

703

answers:

1

I'm trying to set two datakeys using the DataKeyNames property of an asp.net GridView.

I have a simplequery as follows:

Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION> c = new Castle.ActiveRecord.Queries.SimpleQuery<ARMapping.CONFIGURATION>(@"
   select c from CONFIGURATION c left join c.LUserConfiguration luc left join luc.User u left join u.Dealer d left join c.TRUCK t");

In the databind operation, the dealership would be evaluated as follows:

<% Eval("LUserConfiguration.User.Dealer.DealershipID") %>

But when I try to set DataKeyNames="ID,LUserConfiguration.User.Dealer.DealershipID", I get error: " DataBinding: 'ARMapping.CONFIGURATION' does not contain a property with the name 'LUserConfiguration.User.Dealer.DealershipID'. "

It doesn't complain when it's Eval'd, but I can't put Eval in the DataKeyNames property.

Any ideas?

A: 

Following the pattern outlined here, I was able to solve the problem.

A brief explanation... I created a new partial class of the CONFIGURATION class (I did this because my ActiveRecord code is auto-generated, and I couldn't change it. I'm sure this is highly suggested usage anyway, as your models almost always have extended functionality that a partial class is perfect for.

The partial class follows:

Partial Public Class CONFIGURATION

    Public ReadOnly Property GetDealerID() As Integer
     Get
      Return LUserConfigurations.Item(0).Users.Dealer.ID
     End Get
    End Property
End Class

Then, I set the DataKeyNames attribute of the GridView to "ID,GetDealerID". I haven't tested, but the page is loading without error now.

You have to make sure you create a property, not a function (according to the link above).