Print Page | Close Window

Where is OracleIdGenerator?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1304
Printed Date: 28-Mar-2025 at 2:40am


Topic: Where is OracleIdGenerator?
Posted By: skingaby
Subject: Where is OracleIdGenerator?
Date Posted: 04-Jun-2009 at 12:45pm
I am using DevForce Silverlight. What do I need to do to get the business object Id's out of an Oracle Sequence?
Thanks,
Simon



Replies:
Posted By: davidklitzke
Date Posted: 08-Jun-2009 at 9:37am
You can use the same algorithms used in DevForce Classic.  I will email you the documentation used in this tutorial.


Posted By: skingaby
Date Posted: 09-Jun-2009 at 7:27am
I wish I had known I was completely barking up the wrong tree. There is no need to use an IdGenerator.

To use an Oracle Sequence in DevForceEF (Silverlight or Windows):

1) Add a BEFORE INSERT trigger to the table to get the sequence value and put it into the Id column. This will then work in a way similar to a SQL Server identity column.
i.e.:
create or replace trigger DEAL_BI_GETSEQ
before insert on deal FOR EACH ROW when (NEW.DEAL_ID is null)
BEGIN select DEAL_ID_SEQ.nextval into :NEW.DEAL_ID from dual; end;

2) Edit the XML in the Entity Model's .edmx file to add the StoreGeneratedPattern attribute to the key's Property element.
i.e.:
<EntityType Name="DEAL">
          <Key>
            <PropertyRef Name="DEAL_ID" />
          </Key>
          <Property Name="DEAL_ID" Type="int64" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="DATE_ENTERED" Type="DATE" Nullable="false" />
          <Property Name="DATE_OF_DEAL" Type="DATE" Nullable="false" />
          <Property Name="FLOW_DATE_START" Type="DATE" Nullable="false" />
          <Property Name="FLOW_DATE_END" Type="DATE" Nullable="false" />

Now, EF will automagically pick up the new ID and update the item. A unit test like this will show that:
[TestMethod]
public void AddADeal()
{
    ServerModelEF.ModelEntities em = new ModelEntities();
    Deal deal = new Deal();
    long id = deal.DealId;
    em.AddToDeals(deal);
    int result = em.SaveChanges();
    Assert.IsTrue(result>0);
    Assert.AreNotEqual(id, deal.DealId);
}



Print Page | Close Window