Access Modifier & Execute Business Logic During Property Changes

10 posts, 1 answers
  1. Matt.F
    Matt.F avatar
    12 posts
    Member since:
    Jun 2007

    Posted 10 Aug 2010 Link to this post

    Hi There,

    Have just downloaded the most recent internal build of open access (Telerik.OpenAccess_2010_2_0804_5_dev) and have come up with a couple of questions. I'm guessing that there are ways to do what I'm wanting but i'm not going about it the correct way..

    Basically, I have a "User" class set up in my domain model but dont want people to access the "Password" property directly. Instead they should go via the SetPassword() function I've created in my own partial User class. To do this I have set the "Access Modifier" property of the Password MetaProperty to Private, but, it doesnt seem to do anything.. the Password in the User.generated.cs class is still marked as public. I can change it by hand to private but if the class were to ever be regenerated the change would be lost, am I doing something wrong here?

    Also, having read "How to: Execute Business Logic During Property Changes", I can see this will execute business logic when the property is changed but again, wont the changes be lost if any changes are made in the model and the class is regenerated?

    Thanks in advance,

    Matt
  2. Matt.F
    Matt.F avatar
    12 posts
    Member since:
    Jun 2007

    Posted 10 Aug 2010 Link to this post

    # Edit.. updating database from model seems to working again, not sure why.. nothing has changed in the code
  3. DevCraft banner
  4. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 10 Aug 2010 Link to this post

    Hi Matt.F,

    1. Unfortunately, it is not possible to control the access modifier of the properties and it is not possible to have a public property with just a private setter. 
    2. You should create a partial class for User in order to extend it and place your custom logic there. Additional information regarding the partial classes can be found here.
    3. I recommend you reading this help article and blog post which demonstrate how to use custom code generation with Telerik OpenAccess. It is easy to modify the templates to customize the generation of your classes.
    4. Could you please provide us with details regarding your domain model to reproduce the fault behavior? A sample application where the error appears will be highly appreciated. A cached database instance internally used from the product can be the cause for the fault behavior.
    We are looking forward for your reply.


    Greetings,
    Damyan Bogoev
    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
  5. Matt.F
    Matt.F avatar
    12 posts
    Member since:
    Jun 2007

    Posted 10 Aug 2010 Link to this post

    Hi There,

    Thanks for the info on the code generation templates, will look into that further and think it'll prove extremely useful.

    With regards to the password field, the code which is generated at the moment is

           
    private string userPW;
     
    [Column("UserPW", OpenAccessType = OpenAccessType.Varchar, Length = 255, SqlType = "nvarchar")]
    [Storage("userPW")]
    public virtual string UserPW
    {
        get
        {
            return this.userPW;
        }
        set
        {
            this.userPW = value;
        }
    }

    Ideally what I'd like is this:

    private string userPW;
     
    [Column("UserPW", OpenAccessType = OpenAccessType.Varchar, Length = 255, SqlType = "nvarchar")]
    [Storage("userPW")]
    private virtual string UserPW
    {
        get
        {
            return this.userPW;
        }
        set
        {
            this.userPW = value;
        }
    }

    I kinda thought thats what the MetaProperty Access Modifier setting would do but it doesnt do anything.

    With regards to the update database dialogue I'm afraid I cant get it happen again, not sure what the problem was.. seems a restart of visual studio fixed it.

    Thanks again,

    Matt
  6. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 12 Aug 2010 Link to this post

    Hi Matt.F,

    1. Currently the property's Access Modifier setting is not respected during code generation of the class properties, it is only respected on class level. This issue will be improved in the future. We are sorry for he inconvenience this might have caused you.

    We have made a temporary fix for you in one of our templates so you could achieve you goal with a private property after doing the following:
    • Navigate to your OpenAccess installation path and locate the code generation templates for C#. That is usually the: C:\Program Files\Telerik\OpenAccess ORM\dsl\CodeGenerationTemplates\CSharp\Includes folder.
    • Replace the Speciffic.ttinclude template file with the one that I an sending you.
    Your model should now respect the Access modifiers for the properties that are being generated. Please note that this is a temporary fix for you and that the only working scenarios are if you use public or private access modifiers. I hope that is enough for you to solve your issues and continue with your project as planned.

    Regards,
    Damyan Bogoev
    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
  7. Matt.F
    Matt.F avatar
    12 posts
    Member since:
    Jun 2007

    Posted 13 Aug 2010 Link to this post

    That, is absolutely amazing! Never had this level of support from a company before.

    Many thanks, will give that a go and plod along with my project. Hopefully all will be well and we can start using openaccess with larger bit of software. I suspect I will be back at some point soon with more questions..

    Till then,

    thanks

    Matt
  8. Frederik
    Frederik avatar
    12 posts
    Member since:
    May 2009

    Posted 27 Sep 2010 Link to this post

    Hi,

    I had the same problem, and had to 'unlock' the file in the property dialog. It doesn't work in the folder 'C:\Program Files\Telerik\OpenAccess ORM\dsl\CodeGenerationTemplates\CSharp\Includes' - it must to be done in a none system folder. (Windows 7)

    When will the other access modifiers be implemented? I want to use the internal accessor.

    [Edit]
    With a private accessor the compilation fails:
    From the msdn:
    You cannot use the virtual modifier with the static, abstract, private or override modifiers.

    Thanks,
    Freddy
  9. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 Sep 2010 Link to this post

    Hi Frederik,

    We will do our best to implement the requested feature for the next Q3 release.
    I am sorry for the inconvenience caused.

    Kind regards,
    Damyan Bogoev
    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
  10. Jakkie Esschert van den
    Jakkie Esschert van den avatar
    61 posts
    Member since:
    Sep 2009

    Posted 01 Oct 2010 Link to this post

    I just ran into exactly the same issue, for exactly the same reason...

    Will this be taken into account for the DTO templates as well? They will break unless private properties are ignored. 

    Is there an ETA for the Q3 release aready? When it is close enough I will just ignore this problem until after Q3 is released...

  11. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 01 Oct 2010 Link to this post

    Hi Jakkie Esschert van den,

    Yes, we will consider adding this option to the DTO templates as well.
    The Q3 release is scheduled for the middle of November.

    Best wishes,
    Damyan Bogoev
    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
Back to Top
DevCraft banner