How to update my entityfield's value to sysdate

Posts   
 
    
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 14-Nov-2008 03:18:07   

Hi,gus: I'm using version 2.5 I want to update a field to sysdate other than DateTime.Now,because they are different in my programe. I tryed


    myEntity.Fields[(int)myEntityFieldsIndex.UpdateDate].ExpressionToApply=new DbFunctionCall("sysdate",null);
    myEntity.Fields[(int)myEntityFieldsIndex.UpdateDate].IsChanged=true;
    myEntity.IsDirty=true;
    adapter.SaveEntity(myEntity);

It doesn't work. and again try following Create a function named "getmydate" like that Create or replace function getmydate return date is p_result date; begin select sysdate into p_result from dual; return(p_result); end getmydate;


    myEntity.Fields[(int)myEntityFieldsIndex.UpdateDate].ExpressionToApply=new DbFunctionCall("getmydate",null);
    myEntity.Fields[(int)myEntityFieldsIndex.UpdateDate].IsChanged=true;
    myEntity.IsDirty=true;
    adapter.SaveEntity(myEntity);

it doesn't work ,too.

How can i implement this function?Please help me.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Nov-2008 05:18:10   

Hi there,

I'm using this test and seems to work nice against SQLServer 2005:

order.Fields["OrderDate"].ExpressionToApply = new DbFunctionCall("GETDATE", null);
order.Fields["OrderDate"].IsChanged = true;
order.IsDirty = true;

adapter.SaveEntity(order);
  • What exactly "doesn't work" means? (post generated sql, exception details, etc.)
  • Is your "myEntity" properly fetched?
  • What is your LLBLGenPro Runtime library version? (better if you update to the latest build and try again).
David Elizondo | LLBLGen Support Team
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 18-Nov-2008 15:10:59   

daelmo wrote:

Hi there,

I'm using this test and seems to work nice against SQLServer 2005:

order.Fields["OrderDate"].ExpressionToApply = new DbFunctionCall("GETDATE", null);
order.Fields["OrderDate"].IsChanged = true;
order.IsDirty = true;

adapter.SaveEntity(order);
  • What exactly "doesn't work" means? (post generated sql, exception details, etc.)
  • Is your "myEntity" properly fetched?
  • What is your LLBLGenPro Runtime library version? (better if you update to the latest build and try again).

Thank you for apply! I'm using oracle 9i. There isn't a function named "getdate". When I use the second method,no exception throwed,but the value of field [OrderDate] not be updated,it still the original value which of when insert. How to update the value to current date of db server????

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 18-Nov-2008 21:45:10   

To echo David, please post :

Sample code which demonstrates the problem Generated SQL and if possible sql from a trace against the server Your LLBLGen runtime version.

Without these we really struggle to help, as we can only really guess simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Nov-2008 07:27:08   

Also, you can use DBFunctionCall on whatever function you have on DB, not important if it is SQLServer or Oracle. So, for Oracle we have SYSDATE, but SYSDATE isn't really a function, it's a variable. So to get this working you have to write a DB function wrapper, something like:

create or replace function "MYDATE"
return DATE
is
begin
RETURN SYSDATE;
end;

Then, at your .Net code, try this:

order.Fields["OrderDate"].ExpressionToApply = new DbFunctionCall("MyDate", null);
David Elizondo | LLBLGen Support Team
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 19-Nov-2008 13:28:51   

I see.

I'm using LLBLGen in a C/S application.

----------------Client Side---------------------


            BussBorrowEntity b = new BussBorrowEntity(1586);
            b = LLBLServiceManager.FetchEntity(b) as BussBorrowEntity;
            b.Fields[(int)BussBorrowFieldIndex.BorrowTime].ExpressionToApply = new DbFunctionCall("getmydate", null);
            b.Fields[(int)BussBorrowFieldIndex.BorrowTime].IsChanged = true;
            b.IsDirty = true;
            LLBLServiceManager.SaveEntity(b);

------------Server Side--------------------


public class LLBLService : BLServiceBase, ILLBLService
{
        public static bool SaveEntity(CommonEntityBase entity)
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            return adapter.SaveEntity(entity, true, true);
        } 
}

It doesn't work. When I monitor the code in Server Side.The "ExpresionToApplay" of field "BorrowTime" is null. I think when pass the entity from client side to server side,the property is ignored.

but when i use LLBLGen in Server Side only.It get work

-------------------Server Side Only--------------------------


  BussBorrowEntity b = new BussBorrowEntity(1586);
  DataAccessAdapter adapter = new DataAccessAdapter();
  adapter.FetchEntity(b);
  b.Fields[(int)BussBorrowFieldIndex.BorrowTime].ExpressionToApply = new DbFunctionCall("getmydate", null);
  b.Fields[(int)BussBorrowFieldIndex.BorrowTime].IsChanged = true;
  b.IsDirty = true;
  adapter.SaveEntity(b,true,true);

Anyone has the solution?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Nov-2008 16:06:21   

Also how do you pass the entity from the client to the server? WCF, WebServices or Remoting?