public void SaveFoo(string name) { using (IEntityContext entityContext = _entityContextFactory.CreateEntityContext()) { // some EF stuff here entityContext.SaveChanges(); } }
/// <summary> /// Determines whether the Event has a unique DirectUrl. /// </summary> /// <param name="entity">The event.</param> /// <param name="entitytContextFactory">The object context factory.</param> /// <returns> /// <c>true</c> if the Event has a unique DirectUrl; otherwise, <c>false</c>. /// </returns> public static bool HasUniqueDirectUrl(Event entity, IEntityContextFactory entitytContextFactory) { bool result; using (var context = entitytContextFactory.CreateEntityContext()) { var count = context.EntitySet<Event>().Count(e => e.DirectUrl == entity.DirectUrl && e.Id != entity.Id); if (count > 0) { throw new BusinessException( string.Format(CultureInfo.CurrentCulture, "There is already an Event with a direct url of \"{0}\".", entity.DirectUrl)); } result = true; } return result; }
public PatientRatingsHelper(IPatientRatingsSettingsStore settings, IEntityContextFactory entityContext) { _settings = settings.Read(); _objectContext = entityContext.CreateEntityContext().ObjectContext; }