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

CustomBehavior Get/Set a property

11 Answers 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
adi
Top achievements
Rank 1
adi asked on 23 Mar 2011, 02:53 PM
I'd like to know if there is any way to add custom behaviour to the property get/set methods for an entity.
I know there is a "CustomBehavior" for a property but it seems to do nothing.

11 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 24 Mar 2011, 02:22 PM
Hello Andreas,

 There is no way to customize the generated properties however there are a couple of things you can do in this situation. You can either try out our new Fluent Mapping API which is basically a way for you to map your classes through code, this would mean that you could develop your classes with all the custom logic you need directly into your properties. 

Another solution would be to extent the generated classes in partial classes. However using this approach you will only be able to add new properties and not redefine the already defined ones.

There is a third way to achieve your goal however it will require a little more effort on your side. You can modify the T4 templates that we use for code generation and strip off the property generation. Doing so you will be able implement all of your properties in partial classes. You can have a look at this article for more information on customizing our T4 templates.

However you will have to be very careful to define the properties with the same names that would have otherwise been generated. This is required because your model knows about those names and uses that knowledge whenever interpreting LINQ queries. Meaning if the names do not match you will not be able to execute LINQ queries over those properties. 

I hope this is helpful, do let us know if you need further help. 

Greetings,
Serge
the Telerik team
0
Patrice Boissonneault
Top achievements
Rank 2
answered on 18 Apr 2011, 08:57 PM
What is the "CustomBehavior" setting do then?  I'm confused.
0
Serge
Telerik team
answered on 19 Apr 2011, 02:25 PM
Hello Patrice Boissonneault,

 Unfortunately at the moment it does not do anything, it is supposed to be left there so our code generation can just provide a stub for the property and leave you to define this custom behaviour in the partial class. However we do not have such capabilities at the moment.

 I am sorry for any confusion that this has introduced for you.

Greetings,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dan
Top achievements
Rank 1
answered on 14 Feb 2013, 05:10 PM
Has the CustomBehavior/Calculated Storage Behavior - Kind been implemented in newer versions yet?
0
PetarP
Telerik team
answered on 19 Feb 2013, 11:56 AM
Hi Dan,

 I am afraid that this is not yet supported. The best way to increase the priority of that item would be to go to our product feedback portal and suggest the feature there. The more votes the request takes the higher the priority of implementing it will be.

Kind regards,
Petar
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Michael Hildebrand
Top achievements
Rank 2
answered on 30 Mar 2015, 07:06 PM
Hello -

I was wondering if the CustomBehavior property has been implemented yet?  I would like to have a field in the OpenAccess ORM model be 'calculated' (read-only) on the client side.  How can I implement this?

I tried the use of 'partial', but as you have said, it does not let me return values for existing fields.

Thanks.
0
Viktor Zhivkov
Telerik team
answered on 02 Apr 2015, 03:35 PM
Hi Michael,

There are no further improvements in Calculated fields.
I was wondering what do you mean by "...I tried the use of 'partial', but as you have said, it does not let me return values for existing fields...."?
We have advised several clients to add non-persistent properties in a partial class to perform some calculations based on data already available in the records itself.
Please check this simple example:
// generated entity class code
public partial Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
 
// partial extension to the Person class
public partial Person
{
    public string Names { get { return this.FirstName + " " + this.LastName; } }
}

This trick will work as lock as both partial class "pieces" are in the same namespace and the same project.
One of the things to pay attention to is that you have to map your new property (Names in our example) as Transient to instruct Telerik Data Access runtime not to try to use in on database level.

If you have different scenario in mind or have questions about the sample do not hesitate to get back to us.

Regards,
Viktor Zhivkov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Michael Hildebrand
Top achievements
Rank 2
answered on 03 Apr 2015, 11:38 AM

What I meant was when one uses a 'partial', one can not 'redefine' an existing field to return custom data. You have to make up a new field name, as your example shows.

 I see now how to create client side custom fields, thanks for the example.  Is there anyway to have these custom fields show up in the ORM model diagrams?

0
Viktor Zhivkov
Telerik team
answered on 08 Apr 2015, 09:55 AM
Hi Michael,

There is no way to show any extension fields/properties in Visual Designer at the moment. Our intention there was to show only information relevant to the object-relational mapping and "client side" properties have limited value in such context.
If you want visual representation of your classes and their associations you can utilize Visual Studio Class Diagrams. There you will find all class properties plus interfaces, base types and methods. Class Diagrams will also auto update when changes to the included types are saved so you may only want to lay out the types in the best way after you have created the diagram.

Regards,
Viktor Zhivkov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Michael Hildebrand
Top achievements
Rank 2
answered on 01 Jun 2015, 03:07 PM

Hi -

 In the above post you said, "One of the things to pay attention to is that you have to map your new property (Names in our example) as Transient to instruct Telerik Data Access runtime not to try to use in on database level."

How do I set the property to Transient?

0
Viktor Zhivkov
Telerik team
answered on 04 Jun 2015, 08:32 AM
Hello Michael,

Depending on the way your data model is defined you have to use different mean to mark a property as non-persistent (or transient): Apply the appropriate method to your code and run a test that inserts a new records in the database to see that your mapping is valid.

Regards,
Viktor Zhivkov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
General Discussions
Asked by
adi
Top achievements
Rank 1
Answers by
Serge
Telerik team
Patrice Boissonneault
Top achievements
Rank 2
Dan
Top achievements
Rank 1
PetarP
Telerik team
Michael Hildebrand
Top achievements
Rank 2
Viktor Zhivkov
Telerik team
Share this question
or