Assigning Values to Object Properties

6 posts, 0 answers
  1. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 20 Jan 2009 Link to this post

    I have a RadGrid on a page...reading classes generated by Telerik via reverse-mapping. The database table for this specific object has Created and Updated columns, which are Non-Null DateTime. When the grid displays the items, it shows the Created and Updated properties...

    I have set the Created and Updated columns in RadGrid to ReadOnly=True, so that a user cannot edit them nor see them when inserting or editing. Hence, they will not display on the Add New Record form. The problem is that I need the properties of the object that Telerik ORM is inserting to default to the current date/time. I've tried the following:

    1. Setting the _Created and _Updated aliases in the object.vb file if there is a Null or Nothing, didn't work.
    2. Set the values on the Public Sub New() of the object, didn't work.
    3. Set the textbox values during the RadGrid_ItemCreated event...didn't work, in fact it didn't even show up on the Insert Form (Add New Record) when I didn't have the two columns ReadOnly=True. The textboxes were blank, which I thought was odd.
    4. Tried getting the object during the OpenAccessDataSource_Inserting event; seems to be impossible. I've used that technique many times when using an ObjectDataSource, but the OpenAccessDataSource doesn't seem to support this.

    All of the above would be OK at best, if they did work. What I would like is for the object itself to know that it needs to set these properties to Now() when they don't have any values. I usually handled this in the Facade (middle-tier) on other applications, so that the date/time values were always consistent and not reliant upon the client machine or the web server. I do not wish to create a Facade for this lightweight application, so...

    Thanks,
    Mitch
  2. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 21 Jan 2009 Link to this post

    Hi SuperXRAY,
    There are certain issues with OpenAccess data source, and they are being addressed at the moment.
    Could you send us a small sample project, and the appropriate DB schema so that we could test and possibly solve your issues locally? If so, please open a support ticket and attach the zipped files.


    Greetings,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 21 Jan 2009 Link to this post

    Just wanted to update Telerik and whoever else is reading this thread...

    I applied a simple technique of a Base Class, so all of my objects Inherit the Base Class (in this simple case, I called it baseClass.vb).
    I put utility functions in this class, such as the code at the end of this post. So, when my object does a Set method, I change it to this:

    blahblah....
    Set(ByVal Value As DateTime?)  
        Me._updated = ValidateDate(Value)  
    End Set 
     


    While I still prefer something that just overrides the Set method or something, so that I don't have to modify any part of the object, I am getting by for now. The lowDate and highDate used in the function are valid SQL Dates, they aren't meant to represent anything besides valid SQL dates. If anybody has ideas, I'm certainly open.

     

    Public Function ValidateDate(ByVal value As DateTime) As DateTime   
     Dim lowDate As DateTime = "1/1/1753 12:00:00 AM"   
     Dim highDate As DateTime = "12/31/9999 11:59:59 PM"   
     If value > CDate(highDate) Or value < CDate(lowDate) Then   
      'Date is not valid, so set it   
      Return Now()   
     Else   
      Return value   
     End If   
    End Function   
     

     

  5. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 23 Jan 2009 Link to this post

    Hi SuperXRAY,
    You can also implement something like the INotifyPropertyChanged interface (say like the INotifyPropertyChanging in .NET 3.5), implement the universal logic for all the base class properties, and then abstract the logic inside the event handler that handles the PropertyChanged/PropertyChanging events. This is the 'classic' approach to monitoring and processing property changes as far as I recall. Hope this helps.

    Kind regards,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 23 Jan 2009 Link to this post

    This goes along with the support request I made days ago. At this point making a base class that is inherited by all other classes really negates using the ORM Wizard, as it doesn't support inheritance and knows nothing about commonality. That means that once the ORM Wizard is used, it becomes useless, since all of the objects have to be modified individually, and any subsequent changes have to be modified individually as well. As I mentioned in another thread, this is fine for small projects, but doesn't work for big projects, it is simply a nightmare to manage.

    Thanks for your reply, I think I'm just getting very frustrated. There are lots of things that don't appear to be working on our machines.

    Am I to take your response as an answer to the support ticket?
  7. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 24 Jan 2009 Link to this post

    Hi SuperXRAY,
    You can also implement something like the INotifyPropertyChanged interface (say like the INotifyPropertyChanging in .NET 3.5), implement the universal logic for all the base class properties, and then abstract the logic inside the event handler that handles the PropertyChanged/PropertyChanging events. This is the 'classic' approach to monitoring and processing property changes as far as I recall.

    We made some suggestions regarding your post in the forums as well.
    Regarding the missing functionallity in the reverse mapping wizzard:  INdeed currently there is no inheritance functionallity in the reverse-mapping wizard. Only the forward-mapping wizard supports this behavior currently. However there is a possible way to overcome the situation decsribed in the Implementing inheritance in reverse mapped database model Knowledge Base article.

    Please share with us any additional limitations or problems that you might have with OpenAccess, that blocks your implementations.

    Kind regards,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
DevCraft banner