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

Assigning Values to Object Properties

5 Answers 139 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
SuperXRAY
Top achievements
Rank 2
SuperXRAY asked on 21 Jan 2009, 03:54 AM
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

5 Answers, 1 is accepted

Sort by
0
Dimitar Kapitanov
Telerik team
answered on 21 Jan 2009, 09:10 AM
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.
0
SuperXRAY
Top achievements
Rank 2
answered on 22 Jan 2009, 05:17 AM
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   
 

 

0
Dimitar Kapitanov
Telerik team
answered on 23 Jan 2009, 10:10 AM
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.
0
SuperXRAY
Top achievements
Rank 2
answered on 23 Jan 2009, 05:37 PM
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?
0
Dimitar Kapitanov
Telerik team
answered on 24 Jan 2009, 03:36 PM
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.
Tags
Development (API, general questions)
Asked by
SuperXRAY
Top achievements
Rank 2
Answers by
Dimitar Kapitanov
Telerik team
SuperXRAY
Top achievements
Rank 2
Share this question
or