Class EntitiesModel partial and Constructor

4 posts, 0 answers
  1. Olivier
    Olivier avatar
    146 posts
    Member since:
    Nov 2010

    Posted 23 Jan 2015 Link to this post

    Hello

    I have a partial class For EntitiesModel and i have a property type string for this class.


    public partial class EntitiesModel
       {
           #region Déclaration des Propriétés
                
               public string cTableName {
                   get;
                   set;
               }
     
               protected Binding oBind
               {
                   get;
                   set;
               }
           #endregion

    I want to instantiate the property oBind on the constructor
    and the constructor is only static

    How i can write this ?


    static EntitiesModel()
    {
        this.oBind     = new Binding();
         
    }



    thanks
    Olivier




  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 27 Jan 2015 Link to this post

    Hello Olivier,

    In the static constructor you can only initialize static properties. As I see in the first code snippet, the oBind property is not static.

    So depends on what you want to achieve there are two options:
    - If this oBind property should be the same for all instances of EntitiesModel you should declare it as static and initialize it in the static constructor.
    - If the property will be different for different instances of EntitiesModel, you should define a new non static constructor in the partial class where this property is initialized.

    I hope that helps.

    Regards,
    Boris Georgiev
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
  4. Olivier
    Olivier avatar
    146 posts
    Member since:
    Nov 2010

    Posted 27 Jan 2015 in reply to Boris Georgiev Link to this post

    i found a way in my partial class,

    i use Init method

    protected override void Init(string connectionString, string cacheKey, BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer, System.Reflection.Assembly callingAssembly) {
           this.oBind = new Binding();
           base.Init(connectionString, cacheKey, backendConfiguration, metadataContainer, callingAssembly);
       }

    Thanks
    Olivier
  5. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 28 Jan 2015 Link to this post

    Hi Olivier,

    Yes, this is another approach to achieve it.

    If any other questions arise do not hesitate to contact us again.

    Regards,
    Boris Georgiev
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top