/// <summary>
 /// Create a new IP object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 public static IP CreateIP(global::System.Int32 id, global::System.Byte[] address)
 {
     IP iP = new IP();
     iP.Id = id;
     iP.Address = address;
     return iP;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the IPs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToIPs(IP iP)
 {
     base.AddObject("IPs", iP);
 }
        public IP CreateIP(IPAddress address)
        {
            var arr = address.GetAddressBytes();
            var ip = db.IPs.SingleOrDefault(x => x.Address == arr);

            if (ip == null)
            {
                ip = addedIPs.SingleOrDefault(x => x.Address.SequenceEqual(arr));
            }

            if (ip == null)
            {
                ip = new IP
                {
                    Address = arr,
                    Segment = GetIPSegment(address)
                };

                addedIPs.Add(ip);

                db.IPs.AddObject(ip);
            }

            return ip;
        }