As davidklitzke Say I can use Oracle ID Generation Class , I have Made Some Changes to the Class and customize it more.
I make Bold Something You may want to change .
/// <changelog>
/// <item who="jtraband" when="May-09-2002">Created</item>
/// <item who="jtraband" when="Mar-03-2003">Updated for new IIdGenerator signatures</item>
/// </changelog>
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Diagnostics;
using IdeaBlade.Util;
using IdeaBlade.Rdb;
using IdeaBlade.Persistence;
using System.Collections.Generic;
namespace MyEntity
{
// Remember to set the namespace appropriately!
[Serializable]
public class OracleSequenceIdGenerator : IIdGenerator
{
public OracleSequenceIdGenerator() { }
private static string StrSchemaSequance;
/// <summary>
/// Generates a new temporary id for a specified DataColumn
/// Executed on the client only.
/// </summary>
/// <param name="pColumn">RdbColumn for which a new id should be generated</param>
/// <returns>A new temporary id</returns>
public object GetNextTempId(EntityColumn pColumn)
{
Object id = (int)-1 * (mTempIds.Count + 1);
Decimal decimalId = System.Convert.ToDecimal(id);
mTempIds.Add(new UniqueId(pColumn, decimalId));
return decimalId;
}
/// <summary>
/// Determines whether a given id is a temporary id
/// Executed on the client only.
/// </summary>
/// <param name="pUniqueId">Id to be analyzed</param>
/// <returns>true if the id is temporary; otherwise false</returns>
public bool IsTempId(UniqueId pUniqueId)
{
Decimal id = (Decimal)pUniqueId.Value;
return (id < 0);
}
/// <summary>
/// Returns the temporary ids generated since instantiation of this class or the last reset
/// Executed on the client only.
/// </summary>
public UniqueIdCollection TempIds
{
get { return mTempIds; }
}
/// <summary>
/// Reset temporary id generation back to initial state.
/// Executed on the client only.
/// *** Do not call this method if there are any pending temporary ids! ***
/// </summary>
public void Reset()
{
mTempIds.Clear();
}
/// <summary>
/// Returns a dictionary that maps temporary ids to real ids; key = temporary id; value = real id
/// *** Executed on the server-side by the IdeaBlade PersistenceServer ***
/// </summary>
/// <remarks>
/// The requesting client-side PersistenceManager uses the returned map
/// to replace all occurrences of each temporary id (including foreign key references) with its
/// corresponding permanent (real) id.
/// </remarks>
/// <param name="pTempIds">Temporary ids (from client) to map to permanent (real) ids</param>
/// <param name="pAdoHelper">Provides ADO access to the database of this PersistenceServer</param>
/// <returns>An IdeaBlade UniqueIdMap, pairs of {TempIds, PermIds}</returns>
// This method will only be called from the PersistenceServer;
public UniqueIdMap GetRealIdMap(UniqueIdCollection pTempIds, IDataSourceKey pDataSourceKey)
{
UniqueIdMap idMap = new UniqueIdMap();
RdbKey aRdbKey = pDataSourceKey as RdbKey;
mAdoHelper = aRdbKey.AdoHelper;
IList<Decimal> nextIds = GetNextIds(mAdoHelper, pTempIds.Count);
int index = 0;
object nextId;
foreach (UniqueId aUniqueId in pTempIds)
{
if (aUniqueId.Column.DataType == typeof(int))
{
nextId = Convert.ToInt32(nextIds[index]);
} if (aUniqueId.Column.DataType == typeof(Decimal))
{
nextId = Convert.ToDecimal(nextIds[index]);
}
else
{
nextId = nextIds[index];
}
index++;
idMap.Add(aUniqueId, nextId);
}
return idMap;
}
public bool IsApplicable(IDataSourceKey pDsKey)
{
return true;
}
public static string SequanceSchema
{
set { StrSchemaSequance = value; }
get { return StrSchemaSequance; }
}
//***********************************
// Private & Protected
//***********************************
private IList<Decimal> GetNextIds(AdoHelper pAdoHelper, int pCount)
{
String sqlSelect = string.Empty;
sqlSelect = "SELECT " + StrSchemaSequance + ".NEXTVAL FROM DUAL";
List<Decimal> results = new List<Decimal>();
IDbConnection aConnection = pAdoHelper.CreateDbConnection(true);
using (aConnection)
{
aConnection.Open();
IDbCommand aCommand = mAdoHelper.CreateDbCommand(aConnection);
aCommand.CommandText = sqlSelect;
for (int i = 0; i < pCount; i++)
{
Decimal nextId = (Decimal)aCommand.ExecuteScalar();
results.Add(nextId);
}
}
return results;
}
private UniqueIdCollection mTempIds = new UniqueIdCollection(); // Temporary Ids
[NonSerialized]
private AdoHelper mAdoHelper;
}
}
OK that is fine now, I add it to the Entity Project.
New I can call it from Create Method for Call Insert for example:
public static TBLTREE Create(PersistenceManager p, int Idxparent, string Title, int Isform, string Asmname,string Formname, int Isuniq)
{
TBLSYSTEMTREE a = (TBLSYSTEMTREE)p.CreateEntity(typeof(TBLSYSTEMTREE));
MyEntity.OracleSequenceIdGenerator.SequanceSchema = "USYSTEM.IDGENERATORSEQUENCE";
p.GenerateId(a, TBLSYSTEMTREE.IdxEntityColumn);
a.AddToManager();
a.Title = Title;
a.Isform = 0;
a.Asmname = "[test]";
a.Formname = "[no]";
a.Isuniq=0;
return a;
}
You know what is "USYSTEM.IDGENERATORSEQUENCE”yes my Sequance in Oracle Server.
Usystem is Schema for User name “usystem” something like :
CREATE USER usystem
IDENTIFIED BY <Enter User Password Here>
DEFAULT TABLESPACE
TEMPORARY TABLESPACE
And sequance can me make in this Schema:
CREATE SEQUENCE USYSTEM.IDGENERATOR_SEQUENCE
INCREMENT BY 1
START WITH 10
MINVALUE 1
MAXVALUE 999999999999999999999999999
NOCYCLE
NOORDER
CACHE 20
That will work but i want more about when Devforce go from offline to online mode and id mapping, semms it is hard to think how it can work In online transactional system , however I think it might be handel with trigger also small number of records should be added in offline mode, so it might be optional to select statagy from triger or genarator class. Any idea?
Thanks