New Posts New Posts RSS Feed: Where is OracleIdGenerator?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Where is OracleIdGenerator?

 Post Reply Post Reply
Author
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Topic: Where is OracleIdGenerator?
    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);
}
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down