当前位置: 首页>>代码示例>>C#>>正文


C# DbSet.FirstOrDefault方法代码示例

本文整理汇总了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();
        }
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:22,代码来源:ActivityLogTypeMigrator.cs

示例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;
            }
        }
开发者ID:MulderFox,项目名称:Main,代码行数:30,代码来源:ConfigurationSeed.cs

示例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);
 }
开发者ID:SKorolchuk,项目名称:SKASP,代码行数:13,代码来源:DataModels.cs


注:本文中的DbSet.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。