private int ExistingSegment(FawgLineSegment Segment, int LineID)
        {
            using (AdoDataConnection connection = new AdoDataConnection(Connection))
                return(connection.ExecuteScalar <int?>($@"
                    SELECT ID
                    FROM LineSegment
                    WHERE
                    (
	                    SELECT COUNT(AssetConnection.ID) 
	                    FROM AssetConnection
	                    WHERE
		                    AssetConnection.AssetRelationshipTypeID = (SELECT ID FROM AssetRelationshipType WHERE Name = 'Line-LineSegment' ) AND 
		                    ((AssetConnection.ParentID = LineSegment.ID AND AssetConnection.ChildID = {LineID}) OR (AssetConnection.ChildID = LineSegment.ID AND AssetConnection.ParentID = {LineID}))
		
                    ) > 0 AND
                    (
                        SELECT Value 
                        FROM [AdditionalFieldValue] AFV LEFT JOIN [AdditionalField] AF ON AFV.AdditionalFieldID = AF.ID
                        WHERE AF.ParentTable='LineSegment' and AF.FieldName = 'FromBus' AND AFV.ParentTableID = LineSegment.ID 
                    ) = '{Segment.FromBus}' AND 
                    (
                        SELECT Value
                        FROM [AdditionalFieldValue] AFV LEFT JOIN [AdditionalField] AF ON AFV.AdditionalFieldID = AF.ID
                        WHERE AF.ParentTable='LineSegment' and AF.FieldName = 'ToBus' AND AFV.ParentTableID = LineSegment.ID 
                    ) = '{Segment.ToBus}'") ?? -1);
        }
        private bool SegmentChanged(FawgLineSegment Segment, int SegmentID)
        {
            LineSegment original;

            using (AdoDataConnection connection = new AdoDataConnection(Connection))
                original = new TableOperations <LineSegment>(connection).QueryRecordWhere("ID = {0}", SegmentID);
            if (original == null)
            {
                return(true);
            }

            return(original.Length != Segment.Length || original.R0 != Segment.R0 || original.R1 != Segment.R1 ||
                   original.X0 != Segment.X0 || original.X1 != Segment.X1 || original.ThermalRating != Segment.ThermalRating || original.VoltageKV != Segment.VoltageKV);
        }