///<summary>Generates a random primary key without using the cache.</summary>
        public static long GetKeyNoCache(string tablename, string field)
        {
            long rangeStart = 10000;
            long rangeEnd   = long.MaxValue;
            long server_id  = GetServer_id();

            if (server_id != 0)
            {
                ReplicationServer thisServer = ReplicationServers.GetServer(server_id);
                if (thisServer != null && thisServer.RangeEnd - thisServer.RangeStart >= 999999)
                {
                    rangeStart = thisServer.RangeStart;
                    rangeEnd   = thisServer.RangeEnd;
                }
            }
            long span    = rangeEnd - rangeStart;
            long rndLong = (long)(ODRandom.NextDouble() * span) + rangeStart;

            while (rndLong == 0 ||
                   rndLong < rangeStart ||
                   rndLong > rangeEnd ||
                   KeyInUse(tablename, field, rndLong))
            {
                rndLong = (long)(ODRandom.NextDouble() * span) + rangeStart;
            }
            return(rndLong);
        }
        ///<summary>Generates a random primary key.  Tests to see if that key already exists before returning it for use.  The range of returned values is greater than 0, and less than or equal to 9223372036854775807.</summary>
        public static long GetKey(string tablename, string field)
        {
            //No need to check RemotingRole; no call to db.
            //establish the range for this server
            long rangeStart = 10000;
            long rangeEnd   = long.MaxValue;

            //the following line triggers a separate call to db if server_id=-1.  Must be cap.
            if (Server_id != 0)           //if it IS 0, then there is no server_id set.
            {
                ReplicationServer thisServer = GetFirstOrDefault(x => x.ServerId == Server_id);
                if (thisServer != null)                                        //a ReplicationServer row was found for this server_id
                {
                    if (thisServer.RangeEnd - thisServer.RangeStart >= 999999) //and a valid range was entered that was at least 1,000,000
                    {
                        rangeStart = thisServer.RangeStart;
                        rangeEnd   = thisServer.RangeEnd;
                    }
                }
            }
            long rndLong;
            long span = rangeEnd - rangeStart;

            do
            {
                rndLong = (long)(ODRandom.NextDouble() * span) + rangeStart;
            }while(rndLong == 0 ||
                   rndLong < rangeStart ||
                   rndLong > rangeEnd ||
                   KeyInUse(tablename, field, rndLong));
            return(rndLong);
        }