本文整理汇总了C#中DbSet.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# DbSet.FirstOrDefault方法的具体用法?C# DbSet.FirstOrDefault怎么用?C# DbSet.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbSet
的用法示例。
在下文中一共展示了DbSet.FirstOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefaultAdminLanguage
private Language GetDefaultAdminLanguage(DbSet<Setting> settingRecords, DbSet<Language> languageRecords)
{
const string settingKey = "LocalizationSettings.DefaultAdminLanguageId";
var defaultAdminLanguageSetting = settingRecords.FirstOrDefault(x => x.Name == settingKey && x.StoreId == 0);
if (defaultAdminLanguageSetting == null)
defaultAdminLanguageSetting = settingRecords.FirstOrDefault(x => x.Name == settingKey);
if (defaultAdminLanguageSetting != null)
{
var defaultAdminLanguageId = defaultAdminLanguageSetting.Value.ToInt();
if (defaultAdminLanguageId != 0)
{
var language = languageRecords.FirstOrDefault(x => x.Id == defaultAdminLanguageId);
if (language != null)
return language;
}
}
return languageRecords.First();
}
示例2: 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;
}
}
示例3: GetAvatar
/// <summary>
/// The get avatar.
/// </summary>
/// <param name="pictures">
/// The pictures.
/// </param>
/// <returns>
/// The <see cref="Picture"/>.
/// </returns>
public Picture GetAvatar(DbSet<Picture> pictures)
{
return pictures.FirstOrDefault(x => x.PictureId == this.AvatarId);
}