ExpressionToApply in UnitOfWork2 not being applied

Posts   
 
    
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 20-Feb-2008 21:09:11   

Hello,

I have a routine where I am encrypting/decrypting information in a sql server database using the ExpressionToApply property of the field.

I set the property before the item is added to the UnitOfWork2 for saving. If I set a break point at the point where the UOW is commited I can see the ExpressionToApply is set. When I read the trace from the database the insert does not include the Expression. If I call the adapter SaveEntity method it works as expected.

Can anyone help me out with this?

Is there something I am missing?

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Feb-2008 03:55:34   

Hi Harry,

That's weird coz the UOW.Commit uses the SaveEntity routine. Could you please confirm that and paste the code snippets (UOW.Commit vs. adapter.SaveEntity) and the generated SQL. Also post the version of LLBLGen you are using and the runtime libraries version.

I'll try to reproduce it as well with the v2.5.

David Elizondo | LLBLGen Support Team
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 21-Feb-2008 18:34:43   

Here is a snippet from where I am using the UOW.


            DataAccessAdapter localAdapter = new DataAccessAdapter();
            try
            {
                localAdapter.StartTransaction(System.Data.IsolationLevel.ReadUncommitted);
                uow.Commit(localAdapter, false);

                localAdapter.Commit();
                isSaved = true;
            }
            catch (ORMQueryExecutionException ormq)
            {
                Console.WriteLine("---- Offending query ---------");
                Console.WriteLine(ormq.QueryExecuted);
                Console.WriteLine("---- Offending query ---------");
                localAdapter.Rollback();
                throw ormq;
            }
            catch (Exception ex)
            {
                localAdapter.Rollback();
                throw ex;
            }
            finally
            {
            
            }

I have no code for the SaveEntity as we do not use it. I did a test but it was nothing special.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2008 10:19:58   

Please post the code where you set the ExpressionToApply and where you pass the entity to the UOW.

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Mar-2008 13:28:23   

It's been a while since I followed up on this but I was told by another member of my team that it was working. Now I am told that it is not working and its very important.....

Code for setting the expression....


 protected virtual void  EncryptField(IEntityField2 field)
        {
            if (FieldIsEncrypted(field))
            {
                if (field.IsChanged)
                {
                    string cert = FieldEncryptionCert(field);
                    if (cert.Trim().Length > 0)
                    {
                        // Now build replacement expression for insert...
                        // ENCRYPTBYCERT(Cert_ID('#insert cert name here #'),'#insert field value here#')) 
                        DbFunctionCall certId = new DbFunctionCall("CERT_ID", new object[] { cert });
                        field.SetExpression(new DbFunctionCall("ENCRYPTBYCERT", new object[] { certId, field.CurrentValue }));

                    }
                }
            }
        }

Code to call EncryptField...


protected override void OnBeforeEntitySave()
        {
            base.OnBeforeEntitySave();
            // Set database Encryption expressions on fields
            // that we are encrypting at the database level.....
            base.EncryptField(Fields[(int)CarrierOnlineAccessFieldIndex.Password]);
            
        }

Code where entity is added to the UOW...


foreach (CommonEntityBase item in list)
            {
                if (item.IsDirty )
                {
                    uow.AddForSave(item, null, false, false);
                }
            }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Mar-2008 10:39:01   

Not working is a little bit vague for us. Is there and exception (please post it with stack trace)

Else please explain in details what do you mean by it's not working.

Posting the generated SQL would be a Plus simple_smile

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Mar-2008 12:42:30   

Sorry.

I believe I have found my issue. The expression is not being applied when new entities are saved, ie inserted. The expression appears to only be being applied when updated.

I have done some searching in the forums and this appears to be by design.

Is there any intention to add this functionality in future releases?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 18-Mar-2008 15:00:56   

Not for v2.6, so if it will be added, it will be v3.

Frans Bouma | Lead developer LLBLGen Pro
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Mar-2008 15:50:32   

As always I appreciate the help.

You guys do a bang up job!!

Thank you.