template studio....and upgrading LLBLGen...

Posts   
 
    
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 23-Apr-2005 17:58:41   

Hi, I just updated LLBLGen ...2...it is very cool...We like it a lot sunglasses

I have a question regarding the template studio versus custom code into templates.

I changed the Entity.Template to support Audit Trail. I have put some code in the save method like you can see here:


public override bool Save(IPredicate updateRestriction, bool recurse)
        {
            bool transactionStartedInThisScope = false;
            Transaction transactionManager = null;
            
            // **************************
            // CUSTOM AUDIT LOG AUTOMATION
            // Update audit...
            try
            {
                this.AuditConcurrencyDate   = DateTime.Now; // Get the current date
                this.AuditUserID = int.Parse(System.Threading.Thread.CurrentPrincipal.Identity.Name); // Get the current UserID
            }
            catch{}
            // **************************

            if(recurse)
            {
                if(!base.ParticipatesInTransaction)
                {
                    // Start local transaction
                    transactionManager = new Transaction(IsolationLevel.ReadCommitted, "SaveRecursively");
                    // Add ourselves
                    transactionManager.Add(this);
                    transactionStartedInThisScope=true;
                }
            }
            try

....
...

when I upgrade LLBLGen Pro I have to put back my code again. This can be a pain if there was a lot of modifications done in the templates. Is there a way to keep my custom code in the template?

tx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 23-Apr-2005 18:36:44   

You should put the code into an include template which is included in the derived entity. this way you can override Save() and not lose your code. You can also add the Save override to the user code region at the bottom of each derived entity, though that's more work simple_smile . An include template (which is bound to the custom ID for the include template for the derived entity) is the best option for you.

Frans Bouma | Lead developer LLBLGen Pro
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 23-Apr-2005 21:42:58   

Question 1: How Can I override : public override bool Save(IPredicate updateRestriction, bool recurse) in the same class? tx

Question 2: Is it possible to override dbutil.CreateConnection() in a template?


        /// <summary>
        /// Creates a new closed SqlConnection object based on the connection string read from the *.config file of the appdomain.
        /// The connection string is stored in a key with the name defined in the constant connectionKeyString, mentioned above.
        /// </summary>
        /// <returns>A ready to use, closed, sqlconnection object</returns>
        public static SqlConnection CreateConnection()
        {
            if(ActualConnectionString==string.Empty)
            {
                // read the connection string from the *.config file.
                // MyCustom stuff
                ActualConnectionString = MDS.Configuration.DataSettings.DataSources["Conn1"].ConnectionString;
                //AppSettingsReader configReader = new AppSettingsReader();
                //ActualConnectionString = configReader.GetValue(connectionKeyString, typeof(string)).ToString();
            }

            return CreateConnection(ActualConnectionString);
        }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 23-Apr-2005 23:43:19   

Banane wrote:

Question 1: How Can I override : public override bool Save(IPredicate updateRestriction, bool recurse) in the same class? tx

using two class scenario and override it in the derived entity class simple_smile

Question 2: Is it possible to override dbutil.CreateConnection() in a template?


        /// <summary>
        /// Creates a new closed SqlConnection object based on the connection string read from the *.config file of the appdomain.
        /// The connection string is stored in a key with the name defined in the constant connectionKeyString, mentioned above.
        /// </summary>
        /// <returns>A ready to use, closed, sqlconnection object</returns>
        public static SqlConnection CreateConnection()
        {
            if(ActualConnectionString==string.Empty)
            {
                // read the connection string from the *.config file.
                // MyCustom stuff
                ActualConnectionString = MDS.Configuration.DataSettings.DataSources["Conn1"].ConnectionString;
                //AppSettingsReader configReader = new AppSettingsReader();
                //ActualConnectionString = configReader.GetValue(connectionKeyString, typeof(string)).ToString();
            }

            return CreateConnection(ActualConnectionString);
        }

No, but you can create a copy of dbutils and bind that to the dbutils id.

Frans Bouma | Lead developer LLBLGen Pro
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 24-Apr-2005 15:17:59   

sunglasses Q1: Yeah I wanted to use only 1 class schenario but I think it is better if I want to play with template studio 2 use 2 class schenario. smile This is great !

Q2:Yeah that what I'm doing right now...Will it be possible to make the function overridable in the next version?

Tx a lot. It is very fun to use your tools ! sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Apr-2005 10:26:25   

Banane wrote:

sunglasses Q1: Yeah I wanted to use only 1 class schenario but I think it is better if I want to play with template studio 2 use 2 class schenario. smile This is great !

simple_smile

Q2:Yeah that what I'm doing right now...Will it be possible to make the function overridable in the next version?

That's a bit hard, it's a static method, and you can't override a static method. As DbUtils is a very small class, it's pretty simple to make a copy of it and bind the templateid to your copy in which you add your own code.

Tx a lot. It is very fun to use your tools ! sunglasses

smile

Frans Bouma | Lead developer LLBLGen Pro