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

custom code on get object from database

10 Answers 112 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tajes
Top achievements
Rank 1
Tajes asked on 10 Jun 2011, 11:40 AM
Hello everybody!

I'm developing an aplication with an entity object which has a field/property defining its state. This state depends of current date. I'm wondering if is possible to define my own code to check if the state must changes,  that will be executed when the entity object is get from 
database.

Thanks in advance

10 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 14 Jun 2011, 06:55 AM
Hi Jose,

You didn't write if you're using the classic or the Visual Designer approach to OpenAccess?
Nevertheless the solution is almost the same.

You can define a read only getter that is not persisted (that is transient) in your class...OA classes are partial so you can "extend" the generated classes by creating a new code file for the same class and the property definition will be something like (pseudo code)

public partial class MyClass
{
.....

   public MyStateEnum MyState
  {
     get
     {
        if (....some condition using the current date/time)
            return MyStateEnum.State1;
        return MuStateEnum.State2;
     }
  }
}

Hope this makes sense... in the above example I used an enum (the MyStateEnum) to denote the possible states.

Regards

Henrik
0
Tajes
Top achievements
Rank 1
answered on 14 Jun 2011, 09:14 AM
Hello Henrik,

 Thank you for your reply. I'm using Visual Designer approach to OpenAccess. I'm sorry but I didn't write that the state field must be persisted, because it not only depends about the date. Furthermore, I think it cannot be transient to use it in openAccess queries, or at least I get an error when I try to query with a transient property.
0
IT-Als
Top achievements
Rank 1
answered on 14 Jun 2011, 09:18 AM
Hi Jose,

Thanks for elaborating on your thread..

Can you make it work with the property as a persistent property?

Regards

Henrik

0
Tajes
Top achievements
Rank 1
answered on 14 Jun 2011, 09:50 AM
Hi Henrik,
   If I set property as persistent, it works. But then, I can't create code in the getter.
0
IT-Als
Top achievements
Rank 1
answered on 14 Jun 2011, 10:02 AM
Hi Jose,

Yes you can change the getter "logic" but it gets overwritten each time you generate from your diagram again. Anyone at Telerik knows how to overcome this issue?

However, I don't know your exact "logic" for telling the state...  Is this state based on other persistent properties (of the class) in combination with the date/time
Then it is still possible to use a transient field in a partial class. See this.




0
Tajes
Top achievements
Rank 1
answered on 14 Jun 2011, 10:30 AM
Hi Henrik,
   Thank you for your quick replies. I knew to create transient properties in partial class. The problem is that I can not use it in the queries, therefore, when I get an object from database, I must always to check If the state have changed due to current date. The entity has implemented three states: for sale, sold and expired. It has also an expiration date. I will implement more states in the future, so that, I don't want to recode all queries to check new states. If there is any way to check and update state automatically when I get the object from database, I would save a lot of time.
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 14 Jun 2011, 11:52 AM
I still believe transient is the way to go, because of the "dynamic nature" of the logic involved.

Is it possible to construct the (LINQ I guess) query in such a way that some of it (except the transient field) is pushed (evaluated) at the server side and the transient field is evaluated at client side..  For example by "materializing" the objects with a ToList<>() and querying that list against the transient property..

I don't see any event handlers that can help you out...

Regards

Henrik
0
Tajes
Top achievements
Rank 1
answered on 14 Jun 2011, 12:11 PM
Yes, I have think about this way, but I'm afraid  that, first the query and then the ToList<>() conversion will spend much time, because the query get all data from database. I will try it anyway. Thank you so much Henrik, for your time and your help.

Greetings.
0
Ivailo
Telerik team
answered on 14 Nov 2011, 03:38 PM
Hi Eugeniy,

We appreciate your input.

We are going to release Q3 2011 in days, so we will evaluate this idea afterwards and keep you posted once there is any progress.
 

Regards,
Ivailo
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

Tags
Getting Started
Asked by
Tajes
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Tajes
Top achievements
Rank 1
Eugeniy
Top achievements
Rank 2
Ivailo
Telerik team
Share this question
or