Forum:  Databinding and Gui controls

Thread:  How to get IDENTITY Column in PerformWork


Pipo (User)   Posted on: 07-May-2007 15:27:08.
Hello,

LLBLGEN Version 2.0.0.0 Final

I'm using SQL Server 2005. I just wan't to know how i can get the value of an IDENTITY column after inserting the data in the Database. I'm working with ASP.NET Webform and LLBLGenProDataSource2 for databinding. The Source code in the PerformWork Event is:

Code:

protected void _DETAILEDIT_AUFTRAG_OnPerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
{
    using (DataAccessAdapter adapter = new DataAccessAdapter())
    {
     TblVorgangEntity vorgang;
     Int32 id;
     foreach (UnitOfWorkElement2 uow in e.Uow.GetEntityElementsToInsert())
     {
        vorgang = (TblVorgangEntity)uow.Entity;

        vorgang.XxxAnAm = DateTime.Now;
        vorgang.XxxAnVon = (Int32)Session["UID"];
        vorgang.XxxAnWs = "INTRANET 2";
        vorgang.VogAbtId = 15;
     }

     foreach (UnitOfWorkElement2 uow in e.Uow.GetEntityElementsToUpdate())
     {
        vorgang = (TblVorgangEntity)uow.Entity;

        vorgang.XxxGaam = DateTime.Now;
        vorgang.XxxGavon = (Int32)Session["UID"];
        vorgang.XxxGaws = "INTRANET 2";
     }
    
     e.Uow.Commit(adapter, true);

    }

}



I'd tried to run the Reference Manual (both the installed vor VS 2005 and CHM File from your Website) but it doesn't work.

I'm looking forward for your help;-)
Jessynoo (Support Team)   Posted on: 07-May-2007 15:51:32.
Hi,

by default, the overload UnitOfWork.AddForSave(newEntity) is used (refetch = false), but you may intercept the uow elements and set the "Refetch" property to True on the fly.

You may do that in each of the for loops of your code sample.


Pipo (User)   Posted on: 07-May-2007 16:08:28.
i'd tried to do:
Code:

     foreach (UnitOfWorkElement2 uow in e.Uow.GetEntityElementsToInsert())
     {
        uow.Refetch = true;
        vorgang = (TblVorgangEntity)uow.Entity;
        
        vorgang.XxxAnAm = DateTime.Now;
        vorgang.XxxAnVon = (Int32)Session["UID"];
        vorgang.XxxAnWs = "INTRANET 2";
        vorgang.VogAbtId = 15;

     }


Can you explain me how to call the id??
the property is
Code:
vorgang.VogId


Thanks
Jessynoo (Support Team)   Posted on: 07-May-2007 16:10:50.
Well, you should have access to the id just as any other regular field after you performed the uow.commit, simply by calling the corresponding property.

Pipo (User)   Posted on: 07-May-2007 16:37:43.
I' tried this:

Code:
protected void _DETAILEDIT_AUFTRAG_OnPerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
{
    using (DataAccessAdapter adapter = new DataAccessAdapter())
    {
     TblVorgangEntity vorgang;
     Int32 id;
     foreach (UnitOfWorkElement2 uow in e.Uow.GetEntityElementsToInsert())
     {
        uow.Refetch = true;
        vorgang = (TblVorgangEntity)uow.Entity;
        
        vorgang.XxxAnAm = DateTime.Now;
        vorgang.XxxAnVon = (Int32)Session["UID"];
        vorgang.XxxAnWs = "INTRANET 2";
        vorgang.VogAbtId = 15;

     }

     foreach (UnitOfWorkElement2 uow in e.Uow.GetEntityElementsToUpdate())
     {
        vorgang = (TblVorgangEntity)uow.Entity;

        vorgang.XxxGaam = DateTime.Now;
        vorgang.XxxGavon = (Int32)Session["UID"];
        vorgang.XxxGaws = "INTRANET 2";
     }
     e.Uow.Commit(adapter, true);

     vorgang = (TblVorgangEntity)_DETAILEDIT_AUFTRAG.EntityCollection[0];
     id = vorgang.VogId;
    
    }


but id is still 0. The record is inserted in the database, no exeption.

???
Jessynoo (Support Team)   Posted on: 07-May-2007 17:10:45.
Not sure what went wrong here,

but this occurs before the view triggers a global refetch, so the entitycollection property may not be updated yet.

Still, the entities in the uow should have been refetch, so what do you get if you keep browsing the uow elements after commit?