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

Class EntitiesModel partial and Constructor

3 Answers 54 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.
Olivier
Top achievements
Rank 2
Olivier asked on 23 Jan 2015, 04:51 PM
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




3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 27 Jan 2015, 05:58 PM
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.
 
0
Olivier
Top achievements
Rank 2
answered on 27 Jan 2015, 06:49 PM
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
0
Boris Georgiev
Telerik team
answered on 28 Jan 2015, 03:31 PM
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.
 
Tags
General Discussions
Asked by
Olivier
Top achievements
Rank 2
Answers by
Boris Georgiev
Telerik team
Olivier
Top achievements
Rank 2
Share this question
or