dataobjectfield for object with multipart key

dataobjectfield for object with multipart key

Old forum URL: forums.lhotka.net/forums/t/2390.aspx


blp4383 posted on Tuesday, February 20, 2007

The primary key for my object is made up of two fields (and id# and a date).  Do I mark both properties with <DataObjectField(True, True)>?  What's recommended way for dealing with multipart keys. 

Thanks

RockfordLhotka replied on Tuesday, February 20, 2007

Yes, that should work. Remember that the DataObjectField attribute is nothing more than a hint to the Web Forms designer about which properties uniquely identify your object. It isn't a very important attribute in the scheme of things.

What is more important is that your GetIdValue() method in your business object must combine those two values so the result is a single unique value. One common, and simple, solution is to convert them to text and merge them:

Protected Overrides Function GetIdValue() As Object

  Return String.Format("{0},{1}", mId.ToString, mDate.ToString)

End Function

 

Copyright (c) Marimer LLC