本文整理汇总了C#中DbSet.AddOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# DbSet.AddOrUpdate方法的具体用法?C# DbSet.AddOrUpdate怎么用?C# DbSet.AddOrUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbSet
的用法示例。
在下文中一共展示了DbSet.AddOrUpdate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixMeetingTitleTypesAndMeetings
private static void FixMeetingTitleTypesAndMeetings(ref DbContext dbContext, ref DbSet<MeetingTitleType> meetingTitleTypeSet, ref DbSet<Meeting> meetingSet)
{
var meetingTitleType = meetingTitleTypeSet.FirstOrDefault(mtts => mtts.Title == "ST");
if (meetingTitleType == null)
{
meetingTitleType = new MeetingTitleType
{
MeetingType = MeetingType.SetkaniTymu,
Title = "ST"
};
meetingTitleTypeSet.AddOrUpdate(meetingTitleType);
}
else
{
meetingTitleType.MeetingType = MeetingType.SetkaniTymu;
}
dbContext.SaveChanges();
// Nastavit defaultní název setkání týmu
meetingTitleType = meetingTitleTypeSet.First(mtt => mtt.Title == "ST");
Meeting[] meetings = meetingSet.Where(m => m.MeetingType == MeetingType.SetkaniTymu && !m.MeetingTitleTypeId.HasValue).ToArray();
if (meetings.Length == 0)
return;
foreach (Meeting meeting in meetings)
{
meeting.MeetingTitleTypeId = meetingTitleType.MeetingTitleTypeId;
}
}
示例2: FixPhoneNumberPrefixes
private static void FixPhoneNumberPrefixes(ref DbSet<PhoneNumberPrefix> phoneNumberPrefixSet)
{
var phoneNumberPrefixe = new PhoneNumberPrefix
{
PhoneNumberPrefixId = 1,
Title = "CZ +420",
MatchRegex = "^(00420|420).*$",
ReplaceRegex = "^(00420|420)",
ExportablePrefix = "00420"
};
phoneNumberPrefixSet.AddOrUpdate(phoneNumberPrefixe);
}
示例3: FixDistricts
private static void FixDistricts(ref DbSet<District> districtSet)
{
var district = new District
{
DistrictId = 1,
Title = "Mladá Boleslav"
};
districtSet.AddOrUpdate(district);
}