/// <summary>
 /// Create a new SegmentLocation object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="locationId">Initial value of the LocationId property.</param>
 /// <param name="segmentId">Initial value of the SegmentId property.</param>
 public static SegmentLocation CreateSegmentLocation(global::System.Int32 id, global::System.Int32 locationId, global::System.Int32 segmentId)
 {
     SegmentLocation segmentLocation = new SegmentLocation();
     segmentLocation.Id = id;
     segmentLocation.LocationId = locationId;
     segmentLocation.SegmentId = segmentId;
     return segmentLocation;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the SegmentLocations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSegmentLocations(SegmentLocation segmentLocation)
 {
     base.AddObject("SegmentLocations", segmentLocation);
 }
        public Segment CreateSegment(string name, IPAddress subnetMask, IPAddress gateway, Vlan vlan, Location location)
        {
            var subnetMaskArray = subnetMask.GetAddressBytes();
            var gatewayArray = gateway.GetAddressBytes();

            var segment = db.Segments.SingleOrDefault(x => x.Gateway.Address == gatewayArray && x.SubnetMask.Address == subnetMaskArray);

            if (segment == null)
            {
                segment = new Segment
                {
                    Name = name,
                    SubnetMask = CreateIP(subnetMask),
                    Gateway = CreateIP(gateway),
                    Vlan = vlan,
                    IPGroup = GetIPGroup(gateway)
                };

                db.Segments.AddObject(segment);

                var segmentLocation = new SegmentLocation
                {
                    Segment = segment,
                    Location = location
                };

                db.SegmentLocations.AddObject(segmentLocation);
            }

            return segment;
        }