/// <summary> /// Adding new attributes into database. /// </summary> /// <param name="newAttributes">New attribute entity.</param> /// <returns>ID for created attribute.</returns> public int AddAttribute(AdditionalAttribute newAttributes) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newAttributes.ID = context.AdditionalAttributes.NextId(p => p.ID); context.AdditionalAttributes.AddObject(newAttributes); context.SaveChanges(); return newAttributes.ID; } }
private void FixupAdditionalAttribute(AdditionalAttribute previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.Attributes.Contains(this)) { previousValue.Attributes.Remove(this); } if (AdditionalAttribute != null) { if (!AdditionalAttribute.Attributes.Contains(this)) { AdditionalAttribute.Attributes.Add(this); } AdditionalAttributesID = AdditionalAttribute.ID; } else if (!skipKeys) { AdditionalAttributesID = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("AdditionalAttribute") && (ChangeTracker.OriginalValues["AdditionalAttribute"] == AdditionalAttribute)) { ChangeTracker.OriginalValues.Remove("AdditionalAttribute"); } else { ChangeTracker.RecordOriginalValue("AdditionalAttribute", previousValue); } if (AdditionalAttribute != null && !AdditionalAttribute.ChangeTracker.ChangeTrackingEnabled) { AdditionalAttribute.StartTracking(); } } }