CustomBehavior Get/Set a property

12 posts, 0 answers
  1. adi
    adi avatar
    79 posts
    Member since:
    Feb 2007

    Posted 23 Mar 2011 Link to this post

    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.

  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 24 Mar 2011 Link to this post

    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
  3. DevCraft banner
  4. Patrice Boissonneault
    Patrice Boissonneault avatar
    18 posts
    Member since:
    Mar 2010

    Posted 18 Apr 2011 Link to this post

    What is the "CustomBehavior" setting do then?  I'm confused.
  5. Serge
    Admin
    Serge avatar
    375 posts

    Posted 19 Apr 2011 Link to this post

    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
  6. Dan
    Dan avatar
    15 posts
    Member since:
    Mar 2006

    Posted 14 Feb 2013 Link to this post

    Has the CustomBehavior/Calculated Storage Behavior - Kind been implemented in newer versions yet?
  7. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 19 Feb 2013 Link to this post

    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.
  8. Michael Hildebrand
    Michael Hildebrand avatar
    13 posts
    Member since:
    Nov 2004

    Posted 30 Mar 2015 in reply to PetarP Link to this post

    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.
  9. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 02 Apr 2015 Link to this post

    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.
     
  10. Michael Hildebrand
    Michael Hildebrand avatar
    13 posts
    Member since:
    Nov 2004

    Posted 03 Apr 2015 in reply to Viktor Zhivkov Link to this post

    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?

  11. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 08 Apr 2015 Link to this post

    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.
     
  12. Michael Hildebrand
    Michael Hildebrand avatar
    13 posts
    Member since:
    Nov 2004

    Posted 01 Jun 2015 in reply to Viktor Zhivkov Link to this post

    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?

  13. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 04 Jun 2015 Link to this post

    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.
Back to Top
DevCraft banner