Oracle sequence

Posts   
 
    
Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 09-Apr-2008 23:37:42   

I am having a problem when I set a field to be identity / sequence and the appropriate sequence selected. I have tried with both <add key="OracleTriggerSequences" value="true" /> and also set to false. The way the database is setup is, a trigger populates the pk from a sequence automatically when a new record is inserted. Having said that, I tested with the trigger disabled and still get the following error, immediately after the save() operation on an entity.

The error is : 'se.FirstName' threw an exception of type 'System.InvalidCastException'

Here 'se' is an instance of an entity and FirstName is a property. In fact all properties show the same error.

I am using LLBLGen Pro 2.5 final. Self servicing two class. Target .NET Framework 2.0. Oracle Driver is ODP.NET for 10g.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Apr-2008 11:42:13   

The error is : 'se.FirstName' threw an exception of type 'System.InvalidCastException'

What does this have to do with the sequence? Would you please post a complete code snippet and the stack trace?

Also which LLBLGen Pro runtime library are you using?

Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 12-Apr-2008 07:09:18   

I will post a complete code snippet and stack trace on Monday or Tuesday. In the meantime here is a bit more information :

SchoolEntity se = new SchoolENtity();

se.Name = "Royal Primary School"; se.Principal = "Evan Smith";

se.Save();

Right after the save I see the 'System.InvalidCastException'.

The connection to sequence is, school entity represents the school table. This table has a pk field named sid, type is, Number (8,0) and is populated automatically using a trigger which in turn uses a sequence.

The above error is thrown only if I set the identity/sequence property to true and select the appropriate sequence when I generate the DAL using LLBLGen. This error happens regardless of setting <add key="OracleTriggerSequences" value="true" /> or false. I also disabled the trigger and still got the same error. The only way to avoid the error is, to set the identity/sequence property to false and then generating the DAL using LLBLGen.

Next week I will post the stack trace and also the runtime library version number.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Apr-2008 22:02:09   
David Elizondo | LLBLGen Support Team
Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 15-Apr-2008 06:47:54   

Code Fragment :

protected void Button1_Click(object sender, EventArgs e)
{
    //add a new setting.

    SettingEntity se = new SettingEntity();

    se.SName = "KKTest12";
    se.SectorId = 1;
    se.Active = "Y";
    se.UpdateWho = "KK";

    try
    {
        se.Save();
        int sid = se.Sid;
    }
    catch (Exception Ex)
    {
        string err = Ex.Message;
    }
}

The error occurs only when you try to access a property (any property) of the entity and not when you call the Save() method. But the Save() method seems to cause some error internally.

Just to recap, the setting are :

In the LLBLGen Designer: "is identity/sequence" true "read only" true "sequence name" = PPS_CUSTOM.PPS_SID_SEQ

In the web.config file

<add key="OracleTriggerSequences" value="true" />

LLBLGen runtime version v2.0.50727

Exception and StackTrace : System.InvalidCastException was caught Message="Specified cast is not valid." Source="PPS.DAL" StackTrace: at PPS.DAL.EntityClasses.SettingEntityBase.get_Sid() in C:\PPS_DAL\EntityBaseClasses\SettingEntityBase.cs:line 1240 at PPS.DAL.EntityClasses.SettingEntityBase.Refetch() in C:\PPS_DAL\EntityBaseClasses\SettingEntityBase.cs:line 475 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.CheckForRefetch() at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.GetValue(Int32 fieldIndex, Boolean returnDefaultIfNull) at PPS.DAL.EntityClasses.SettingEntityBase.get_Sid() in C:\PPS_DAL\EntityBaseClasses\SettingEntityBase.cs:line 1240 at Test.Button1_Click(Object sender, EventArgs e) in d:\Documents and Settings\kkrishna\My Documents\Visual Studio 2005\WebSites\PPS\Test.aspx.cs:line 35 InnerException:

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Apr-2008 12:14:56   

LLBLGen runtime version v2.0.50727

That's not the runtime library version. Please consult the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722

Just for the sake of trial, would you please use the designer to refresh the Catalog and re-generate the code, I have a feeling that the underlying database might not match the generated persistence info.

Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 16-Apr-2008 02:16:45   

The file version is : 2.5.8.122

What is the difference between file version and assembly version?

I will try what you have suggested and post again.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 16-Apr-2008 11:19:08   

File version is the build number. Assembly version doesn't change during releases.

Frans Bouma | Lead developer LLBLGen Pro