本文整理汇总了C#中ObjectContext.DeleteObject方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContext.DeleteObject方法的具体用法?C# ObjectContext.DeleteObject怎么用?C# ObjectContext.DeleteObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectContext
的用法示例。
在下文中一共展示了ObjectContext.DeleteObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveObject
/// <summary>
/// Removes specified data object.
/// </summary>
/// <param name="context">ObjectContext object</param>
/// <param name="obj">Data object to remove</param>
/// <returns>
/// entity set name
/// </returns>
public static void RemoveObject(ObjectContext context,
DataObject obj)
{
Debug.Assert(context != null);
context.DeleteObject(DataObjectHelper.GetEntityObject(obj));
}
示例2: DeleteObject
protected void DeleteObject(ObjectContext context, object entity)
{
try
{
context.DeleteObject(entity);
}
catch (Exception ex)
{
throw new EntityContextException("DeleteObject failed.", ex);
}
}
示例3: UpdateEventType
public static void UpdateEventType(Event target, IEnumerable<int> eventTypeIds, ObjectContext objectContext)
{
if (eventTypeIds.Count() > 0)
{
target.EventTypeAssociations.ToList().ForEach(e => objectContext.DeleteObject(e));
foreach (var typeId in eventTypeIds)
target.EventTypeAssociations.Add(new EventTypeAssociation() { EventTypeId = typeId, EventId = target.Id });
}
else
throw new BusinessException("Event Type requires at least one value");
}
示例4: Add
/// <summary>
/// Registers the attended for the specific event.
/// </summary>
/// <param name="occurence">The event occurence.</param>
/// <param name="registration">The event registration.</param>
/// <param name="attendee">The attendee.</param>
/// <param name="amountPaid">The amount paid.</param>
/// <param name="userProfile">The user profile.</param>
/// <param name="sessionId">The session id.</param>
/// <param name="context">The Object Context</param>
/// <param name="discountCode">The Discount Code used</param>
/// <param name="forcePayLater">Flag weather or not to force the PaymentRequired to true</param>
public static void Add(EventOccurrence occurence, EventRegistration registration, EventAttendee attendee, decimal amountPaid, UserProfile userProfile, string sessionId, ObjectContext context, string discountCode, bool forcePayLater)
{
if (!string.IsNullOrEmpty(discountCode))
attendee.DiscountCodeId = FindDiscountCodeId(discountCode, occurence.Id, context);
var paymentRequired = (forcePayLater || occurence.AllowPayOnSite && amountPaid == 0 && occurence.Cost > 0) ? true : false;
occurence.RegisterAttendee(registration, attendee, amountPaid, paymentRequired);
AddActivity(userProfile, attendee.Name, occurence, sessionId);
UpdateProfileEventCart(userProfile);
var notificationSubscriber = occurence.EventOccurrenceNotifications.SingleOrDefault(n => string.Equals(n.Email, attendee.Email.Value, System.StringComparison.OrdinalIgnoreCase));
if (notificationSubscriber != null)
context.DeleteObject(notificationSubscriber);
}
示例5: AddExternalIdMapping
public static void AddExternalIdMapping(ObjectContext context, EventV2 source, Event theEvent)
{
if (!string.IsNullOrEmpty(source.EventExternalId))
{
var existingMappings = context.CreateObjectSet<DataImportEntityIdMap>()
.Where(m => m.EntityName == "Event" && m.InternalId == theEvent.Id)
.ToList();
if (existingMappings.Count == 1)
{
if (existingMappings[0].ExternalId != source.EventExternalId)
{
// Update ExternalId on existing mapping
existingMappings[0].ExternalId = source.EventExternalId;
}
}
else
{
// Remove ambiguous mappings (if any)
if (existingMappings.Count > 1)
{
foreach (var mapping in existingMappings)
{
context.DeleteObject(mapping);
}
}
// Create new mapping
context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap
{
EntityName = "Event",
DataImportId = 2,
InternalId = theEvent.Id,
ExternalId = source.EventExternalId
});
}
}
}
示例6: SetServices
private static ICollection<ProviderOrgUnitService> SetServices(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, ICollection<ProviderOrgUnitService> existingServices)
{
if (source.Services == null)
return existingServices;
try
{
//Delete existing services to be sure they are not duplicated.
existingServices.ToList().ForEach(s => context.DeleteObject(s));
var Services = context.CreateObjectSet<Service>();
var providerOrgUnitServices = new List<ProviderOrgUnitService>();
foreach (ProviderOrgUnitServiceV2 item in source.Services)
{
if (string.IsNullOrEmpty(item.Name))
continue;
//Ensure Service Exists
var service = Services.FirstOrDefault(s => s.Name == item.Name);
if (service == null)
{
service = new Service
{
Name = item.Name,
IsEnabled = true
};
Services.AddObject(service);
}
providerOrgUnitServices.Add(new ProviderOrgUnitService(service));
}
return providerOrgUnitServices;
}
catch (Exception ex)
{
throw new BusinessException("Error processing services for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例7: SetSchedules
private static ICollection<ProviderOrgUnitSchedule> SetSchedules(ObjectContext context, ProviderOrgUnitV2 item, ICollection<ProviderOrgUnitSchedule> existingSchedules)
{
if (item.Schedules == null)
return existingSchedules;
//Delete existing schedules to be sure they are not duplicated.
existingSchedules.ToList().ForEach(s => context.DeleteObject(s));
var list = new List<ProviderOrgUnitSchedule>();
foreach (ProviderOrgUnitScheduleV2 schedule in item.Schedules)
{
list.Add(new ProviderOrgUnitSchedule(new ScheduleTimeSpan(ResolveOpenTime(schedule), ResolveOpenHours(schedule))));
}
return list;
}
示例8: SetInsurances
private static ICollection<ProviderOrgUnitInsurance> SetInsurances(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, int orgUnitId, ICollection<ProviderOrgUnitInsurance> existingInsurances)
{
if (source.Insurances == null)
return existingInsurances;
try
{
//Delete existing insurances to be sure they are not duplicated.
existingInsurances.ToList().ForEach(i => context.DeleteObject(i));
var insurances = context.CreateObjectSet<Insurance>();
var orgUnits = context.CreateObjectSet<OrgUnit>();
var providerOrgUnitInsurances = new List<ProviderOrgUnitInsurance>();
foreach (ProviderOrgUnitInsuranceV2 item in source.Insurances)
{
if (string.IsNullOrEmpty(item.Name))
continue;
//Ensure Insurance Exists
var insurance = insurances.FirstOrDefault(s => s.Name == item.Name);
if (insurance == null)
{
insurance = new Insurance(item.Name, true);
insurances.AddObject(insurance);
}
if (!orgUnits.Single(ou => ou.Id == orgUnitId).OrgUnitPublished.InsurancesOrgUnit.OrgUnitInsurances.Any(i => i.InsuranceId == insurance.Id))
providerOrgUnitInsurances.Add(new ProviderOrgUnitInsurance(insurance));
}
return providerOrgUnitInsurances;
}
catch (Exception ex)
{
throw new BusinessException("Error processing insurances for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例9: SetDisabledInheritedInsurances
private static ICollection<ProviderOrgUnitInsurancesInheritedDisabled> SetDisabledInheritedInsurances(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, ICollection<ProviderOrgUnitInsurancesInheritedDisabled> existingInsurancesDisabled)
{
if (source.DisabledInheritedInsurances == null)
return existingInsurancesDisabled;
try
{
//Delete existing insurances to be sure they are not duplicated.
existingInsurancesDisabled.ToList().ForEach(i => context.DeleteObject(i));
var insurances = context.CreateObjectSet<Insurance>();
var disabledInheritedInsurances = new List<ProviderOrgUnitInsurancesInheritedDisabled>();
foreach (DisabledInheritedInsuranceV2 item in source.DisabledInheritedInsurances)
{
//Ensure Insurance Exists
var insurance = insurances.FirstOrDefault(s => s.Name == item.Name);
if (insurance == null)
{
continue;
}
disabledInheritedInsurances.Add(new ProviderOrgUnitInsurancesInheritedDisabled
{
Insurance = insurance
});
}
return disabledInheritedInsurances;
}
catch (Exception ex)
{
throw new BusinessException("Error processing disabled inherited insurances for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例10: SetProviderSpecialties
public static void SetProviderSpecialties(ObjectContext context, ProviderV2 source, Provider provider)
{
if (source.Specialties == null)
return;
try
{
foreach (var item in provider.ProviderSpecialties.ToArray())
context.DeleteObject(item);
var specialtiesObjectSet = context.CreateObjectSet<Specialty>();
//Get all referenced parent specialties
var uniqueParentSpecialties = source.Specialties
.Where(s => !string.IsNullOrEmpty(s.ParentSpecialtyName))
.Select(s => new KeyValuePair<string, string>(s.ParentSpecialtyName, s.SpecialtyType))
.Distinct();
//Ensure parent specialties exist
var parentSpecialties = EnsureParentSpecialtiesExist(uniqueParentSpecialties, specialtiesObjectSet);
var providerSpecialties = new List<ProviderSpecialty>();
foreach (var item in source.Specialties)
{
var specialty = specialtiesObjectSet.FirstOrDefault(s => s.Name == item.SpecialtyName);
if (specialty == null)
{
specialty = parentSpecialties.FirstOrDefault(s => s.Name == item.SpecialtyName);
if (specialty == null)
{
var specialtyType = string.IsNullOrEmpty(item.SpecialtyType) ? SpecialtyType.Specialty : item.SpecialtyType;
specialty = new Specialty() { Name = item.SpecialtyName, IsEnabled = true, SpecialtyType = specialtyType };
if (!string.IsNullOrEmpty(item.ParentSpecialtyName))
{
specialty.ParentSpecialty = parentSpecialties.FirstOrDefault(s => s.Name == item.ParentSpecialtyName && s.SpecialtyType == specialtyType);
}
specialtiesObjectSet.AddObject(specialty);
}
}
providerSpecialties.Add(new ProviderSpecialty(provider, specialty)
{
IsBoardCertified = ConvertToBool(item.IsBoardCertified, false, "Specialty/IsBoardCertified", provider.FullName),
IsPrimary = ConvertToBool(item.IsPrimary, false, "Specialty/IsPrimary", provider.FullName),
});
}
provider.ProviderSpecialties = providerSpecialties;
}
catch (Exception ex)
{
throw new BusinessException("Error processing specialties for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例11: SetOrgUnitServices
public static void SetOrgUnitServices(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
{
//ignore null values
if (source.OrgUnitServices == null)
return;
try
{
var existingServices = orgUnit.OrgUnitServices.ToArray();
foreach (var item in existingServices)
context.DeleteObject(item);
var services = context.CreateObjectSet<Service>();
var orgUnitServices = new List<OrgUnitService>();
foreach (var item in source.OrgUnitServices)
{
//Ensure service Exists
var service = services.FirstOrDefault(i => i.Name == item.Name);
if (service == null)
{
service = new Service()
{
Name = item.Name,
IsEnabled = true
};
services.AddObject(service);
}
orgUnitServices.Add(new OrgUnitService
{
Service = service,
OrgUnit = orgUnit
});
}
orgUnit.OrgUnitServices = orgUnitServices;
}
catch (Exception ex)
{
throw new BusinessException("Error processing services for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
}
}
示例12: SetOrgUnitDiscountCodes
public static void SetOrgUnitDiscountCodes(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
{
//ignore null values
if (source.OrgUnitDiscountCodes == null)
return;
try
{
var existingOrgUnitDiscountCodes = orgUnit.OrgUnitDiscountCodes.ToArray();
foreach (var item in existingOrgUnitDiscountCodes)
context.DeleteObject(item);
var discountCodes = context.CreateObjectSet<DiscountCode>();
var orgUnitDiscountCodes = new List<OrgUnitDiscountCode>();
foreach (var item in source.OrgUnitDiscountCodes)
{
//Check if discount code exists
var discountCode = discountCodes.FirstOrDefault(i => i.Code == item.Code);
//If the discount code doesn't exist, create a new one
if (discountCode == null)
{
discountCode = new DiscountCode()
{
Code = item.Code,
Description = item.Description,
DiscountTypeId = LookupDiscountType(context, item.DiscountType),
IsEnabled = item.IsEnabled.ToString().ToUpperInvariant() == "TRUE" ? true : false,
IsFromOrgUnit = true,
IsGroupCode = item.IsGroupCode.ToString().ToUpperInvariant() == "TRUE" ? true : false,
};
int requiredGroupSize;
if (int.TryParse(item.RequiredGroupSize.ToString(), out requiredGroupSize))
discountCode.RequiredGroupSize = requiredGroupSize;
decimal discountValue;
if (decimal.TryParse(item.DiscountValue, out discountValue))
discountCode.DiscountValue = discountValue;
DateTime startDate;
if (DateTime.TryParse(item.StartDate, out startDate))
discountCode.StartDate = startDate;
DateTime endDate;
if (DateTime.TryParse(item.EndDate, out endDate))
discountCode.EndDate = endDate;
discountCodes.AddObject(discountCode);
}
else
{
//Ensure existing discount code is not an Event discount code
if (!discountCode.IsFromOrgUnit)
{
throw new BusinessException("Discount code already in use by an Event.");
}
UpdateExistingCode(context, discountCode, item);
}
var newOrgUnitDiscountCode = new OrgUnitDiscountCode();
var codeWithId = discountCodes.FirstOrDefault(d => d.Code == discountCode.Code);
newOrgUnitDiscountCode.DiscountCodeId = codeWithId == null ? 0 : codeWithId.Id;
newOrgUnitDiscountCode.DiscountCode = discountCode;
int orgUnitId;
if (int.TryParse(source.CopiedInternalId, out orgUnitId))
newOrgUnitDiscountCode.OrgUnitId = orgUnitId;
orgUnitDiscountCodes.Add(newOrgUnitDiscountCode);
}
orgUnit.OrgUnitDiscountCodes = orgUnitDiscountCodes;
}
catch (Exception ex)
{
throw new BusinessException("Error processing OrgUnitDiscountCodes for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
}
}
示例13: SetProviderEducationTypes
public static void SetProviderEducationTypes(ObjectContext context, ProviderV2 source, Provider provider)
{
if (source.EducationTypes == null)
return;
try
{
var existingEducationTypes = provider.ProviderEducations.ToArray();
foreach (var item in existingEducationTypes)
context.DeleteObject(item);
var educationTypes = context.CreateObjectSet<EducationType>();
var providerEducations = new List<ProviderEducation>();
foreach (var item in source.EducationTypes)
{
//Ensure Education Type Exists
var education = educationTypes.FirstOrDefault(s => s.Name == item.EducationTypeName);
if (education == null)
{
education = new EducationType(item.EducationTypeName, true);
educationTypes.AddObject(education);
}
var addedEducation = new ProviderEducation(provider, education, item.InstitutionName);
addedEducation.SetYearCompleted(item.YearCompleted);
if (ConvertToBool(item.IsComplete, false, "Education/IsCompleted", provider.Name) || !string.IsNullOrEmpty(item.YearCompleted))
addedEducation.IsCompleted = true;
providerEducations.Add(addedEducation);
}
provider.ProviderEducations = providerEducations;
}
catch (Exception ex)
{
throw new BusinessException("Error processing educations for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例14: SetProviderLanguages
public static void SetProviderLanguages(ObjectContext context, ProviderV2 source, Provider provider)
{
if (source.Languages == null)
return;
try
{
var existingLanguages = provider.ProviderLanguages.ToArray();
foreach (var item in existingLanguages)
context.DeleteObject(item);
var languages = context.CreateObjectSet<Language>();
var providerLanguages = new List<ProviderLanguage>();
foreach (var item in source.Languages)
{
//Ensure Language Exists
var language = languages.FirstOrDefault(s => s.Name == item.LanguageName);
if (language == null)
{
language = new Language(true, 0, item.LanguageName, true);
languages.AddObject(language);
}
providerLanguages.Add(new ProviderLanguage(provider, language, ConvertToBool(item.IsPrimary, false, "Language/IsPrimary", provider.FullName))
{
IsFluent = ConvertToBool(item.IsFluent, false, "Language/IsFluent", provider.FullName)
});
}
provider.ProviderLanguages = providerLanguages;
}
catch (Exception ex)
{
throw new BusinessException("Error processing languages for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}
示例15: SetProviderClinicalInterests
public static void SetProviderClinicalInterests(ObjectContext context, ProviderV2 source, Provider provider)
{
if (source.ClinicalInterests == null)
return;
try
{
var existingClinicalInterests = provider.ProviderClinicalInterests.ToArray();
foreach (var item in existingClinicalInterests)
context.DeleteObject(item);
var clinicalInterests = context.CreateObjectSet<ClinicalInterest>();
var providerClinicalInterests = new List<ProviderClinicalInterest>();
foreach (var item in source.ClinicalInterests)
{
//Ensure Clinical Interest Exists
var clinicalInterest = clinicalInterests.FirstOrDefault(s => s.Name == item.Name);
if (clinicalInterest == null)
{
clinicalInterest = new ClinicalInterest(item.Name, true);
clinicalInterests.AddObject(clinicalInterest);
}
providerClinicalInterests.Add(new ProviderClinicalInterest(provider, clinicalInterest));
}
provider.ProviderClinicalInterests = providerClinicalInterests;
}
catch (Exception ex)
{
throw new BusinessException("Error processing clinical interests for provider '" + provider.Name + "' - " + ex.Message, ex);
}
}