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


C# DbSet.Where方法代码示例

本文整理汇总了C#中DbSet.Where方法的典型用法代码示例。如果您正苦于以下问题:C# DbSet.Where方法的具体用法?C# DbSet.Where怎么用?C# DbSet.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbSet的用法示例。


在下文中一共展示了DbSet.Where方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteSalesByVendor

        private void WriteSalesByVendor(
            XmlTextWriter writer, DbSet<Models.Sale> sales, Models.Vendor vendor)
        {
            writer.WriteStartElement("sale");
            writer.WriteAttributeString("vendor", vendor.VendorName);
            foreach (var date in sales.Where(s => s.Product.VendorID == vendor.ID)
                .Select(s => s.Date).Distinct().ToList())
            {
                writer.WriteStartElement("summary");
                writer.WriteAttributeString("date", date.ToShortDateString());
                writer.WriteAttributeString("total-sum", sales.Where(s => s.Date == date &&
                    s.Product.VendorID == vendor.ID).Sum(s => s.Sum).ToString());
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
开发者ID:krasimirkrustev,项目名称:ta-supermarket-teamproject,代码行数:17,代码来源:XmlSalesReportByVendorsCreator.cs

示例2: GetFilteredSubmissions

        internal IQueryable<Submission> GetFilteredSubmissions(DbSet<Submission> submissions, string[] filter)
        {
            if (filter == null || filter.Length == 0)
            {
                filter = new [] { "sfw" };
            }

            return submissions.Where(x => filter.Any(f => f.ToLower() == x.Tag.ToString().ToLower()));
        }
开发者ID:codercae,项目名称:Chreytli.Api,代码行数:9,代码来源:SubmissionsBusinessController.cs

示例3: ValidateProductData

        private string ValidateProductData(DbSet<Product> dbSet, Product product, bool isNew)
        {
            if (String.IsNullOrEmpty(product.Article))
                return "Артикул товара обязателен";

            if(product.Supplier == null)
                return "Не указан поставщик товара";

            if (isNew)
            {
                Product item = dbSet.Where(x =>
                    String.Compare(x.Article, product.Article, StringComparison.OrdinalIgnoreCase) == 0
                    && x.ContractorId == product.Supplier.ContractorId).FirstOrDefault<Product>();

                if (item != null)
                    return "Товар с таким артикулом существует";

                product.CreatedAt = DateTime.Now;
            }
            else
            {
                Product item = (from x in dbSet
                                   where x.ProductId == product.ProductId
                                   select x).First<Product>();

                // if Article was changed
                if (item.Article.ToLower() != product.Article.ToLower())
                {
                    if ((from x in dbSet
                         where String.Compare(x.Article, product.Article, StringComparison.OrdinalIgnoreCase) == 0
                         select x).FirstOrDefault<Product>() != null)
                        return "Товар с таким артикулом существует";
                }

                product.ModifiedAt = DateTime.Now;
            }

            return String.Empty;
        }
开发者ID:sidby,项目名称:sklad,代码行数:39,代码来源:ReferenceController.cs

示例4: ValidateContractorData

        private string ValidateContractorData(DbSet<Contractor> dbSet, Contractor contractor, bool isNew)
        {
            if (String.IsNullOrEmpty(contractor.Name))
                return "Имя пользователя обязательно";

            if (String.IsNullOrEmpty(contractor.Code))
                return "Отображаемое имя обязательно";

            if (isNew)
            {
                Contractor item = dbSet.Where(x =>
                    String.Compare(x.Code, contractor.Code, StringComparison.OrdinalIgnoreCase) == 0
                    || x.Name == contractor.Name).FirstOrDefault<Contractor>();

                if (item != null)
                    return "Контрагент с таким именем существует";
            }
            else
            {
                Contractor item = (from x in dbSet
                                   where x.ContractorId == contractor.ContractorId
                                   select x).First<Contractor>();

                // if DisplayName was changed
                if (item.Name.ToLower() != contractor.Name.ToLower())
                {
                    if ((from x in dbSet
                         where String.Compare(x.Name, contractor.Name, StringComparison.OrdinalIgnoreCase) == 0
                         select x).FirstOrDefault<Contractor>() != null)
                        return "Контрагент с таким именем существует";
                }

                // if UserName was changed
                if (item.Code.ToLower() != contractor.Code.ToLower())
                {
                    if ((from x in dbSet
                         where String.Compare(x.Code, contractor.Code, StringComparison.OrdinalIgnoreCase) == 0
                         select x).FirstOrDefault<Contractor>() != null)
                        return "Контрагент с таким именем существует";
                }
            }

            if (!String.IsNullOrEmpty(contractor.Email))
            {
                if (!ValidationHelper.IsValidEmail(contractor.Email))
                    return "Неверный формат email";
            }

            return String.Empty;
        }
开发者ID:sidby,项目名称:sklad,代码行数:50,代码来源:ReferenceController.cs

示例5: GetLabelEntity

 private IQueryable<LabelEntity> GetLabelEntity(DbSet<LabelEntity> labels, Label label)
 {
     if (!string.IsNullOrEmpty(label.Name))
     {
         return labels.Where(it => it.SiteName == label.Site.FullName && it.Name == label.Name && it.Category == (label.Category ?? ""));
     }
     else
     {
         return labels.Where(it => it.SiteName == label.Site.FullName && it.UUID == label.UUID);
     }
 }
开发者ID:Godoy,项目名称:CMS,代码行数:11,代码来源:LabelProvider.cs

示例6: 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

示例7: FixBankAccountsAndMeetings

        private static void FixBankAccountsAndMeetings(ref DbSet<BankAccount> bankAccountSet, ref DbSet<Meeting> meetingSet)
        {
            Meeting[] meetings = meetingSet.Where(m => m.Finished > DateTime.Now).ToArray();
            BankAccount[] bankAccounts = bankAccountSet.Where(ba => ba.Token != "V2-1-0-21").ToArray();
            foreach (Meeting meeting in meetings)
            {
                BankAccountType bankAccountType;
                switch (meeting.MeetingType)
                {
                    case MeetingType.Lgs:
                    case MeetingType.WorkshopyBi:
                    case MeetingType.Leaders:
                    case MeetingType.MspEvening:
                        bankAccountType = BankAccountType.LgsOrMspEveningOrWorkshopsOrLeaders;
                        break;

                    case MeetingType.SetkaniTymu:
                        bankAccountType = BankAccountType.TeamMeeting;
                        break;

                    case MeetingType.SkoleniDavidaKotaska:
                        bankAccountType = BankAccountType.DavidKotasekTraining;
                        break;

                    case MeetingType.Ostatni:
                        bankAccountType = BankAccountType.Others;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }

                BankAccount bankAccount = bankAccounts.FirstOrDefault(ba => ba.CurrencyType == CurrencyType.CZK && ba.BankAccountType == bankAccountType);
                if (bankAccount == null)
                    continue;

                meeting.BankAccountId = bankAccount.BankAccountId;
            }

            bankAccounts = bankAccountSet.Where(ba => ba.Title == String.Empty && ba.Token != "V2-1-0-21").ToArray();
            foreach (BankAccount bankAccount in bankAccounts)
            {
                bankAccount.Title = bankAccount.BankAccountTypeLocalizedText;
                bankAccount.Owner = bankAccount.BankAccountTypeLocalizedText;
            }

            bankAccounts = bankAccountSet.Where(ba => ba.Token == "V2-1-0-21").ToArray();
            foreach (BankAccount bankAccount in bankAccounts)
            {
                bankAccountSet.Remove(bankAccount);
            }
        }
开发者ID:MulderFox,项目名称:Main,代码行数:52,代码来源:ConfigurationSeed.cs

示例8: ValidateUsersData

        private string ValidateUsersData(DbSet<UserProfile> dbSet, UserProfile profile, bool isNew)
        {
            if (String.IsNullOrEmpty(profile.UserName))
                return "Имя пользователя обязательно";

            if (String.IsNullOrEmpty(profile.DisplayName))
                return "Отображаемое имя обязательно";

            if (isNew)
            {
                UserProfile item = dbSet.Where(x =>
                    String.Compare(x.DisplayName, profile.DisplayName, StringComparison.OrdinalIgnoreCase) == 0
                    || x.UserName == profile.UserName).FirstOrDefault<UserProfile>();

                if (item != null)
                    return "Пользователь с таким именем существует";
            }
            else
            {
                UserProfile item = (from x in dbSet
                                    where x.UserId == profile.UserId
                                    select x).First<UserProfile>();

                // if DisplayName was changed
                if (item.DisplayName.ToLower() != profile.DisplayName.ToLower())
                {
                    if ((from x in dbSet
                         where x.DisplayName == profile.DisplayName
                         select x).FirstOrDefault<UserProfile>() != null)
                        return "Пользователь с таким именем существует";
                }

                // if UserName was changed
                if (item.UserName.ToLower() != profile.UserName.ToLower())
                {
                    if ((from x in dbSet
                         where x.UserName == profile.UserName
                         select x).FirstOrDefault<UserProfile>() != null)
                        return "Пользователь с таким именем существует";
                }
            }

            if (!String.IsNullOrEmpty(profile.UserEmail))
            {
                if (!ValidationHelper.IsValidEmail(profile.UserEmail))
                    return "Неверный формат email";
            }

            return String.Empty;
        }
开发者ID:sidby,项目名称:sklad,代码行数:50,代码来源:MyCompanyController.cs

示例9: createSomeWorkers

        public bool createSomeWorkers(int numWorkers, DbSet<Worker> workers)
        {
            for (int i = numWorkers; i >= 0; --i)
            {
                Person _per = (Person)Records.person.Clone();
                Worker _wkr = (Worker)Records.worker.Clone();
                Random rnd = new Random();

                while (workers.Where(q => q.dwccardnum == _wkr.dwccardnum).Count() > 0)
                {
                    _wkr.dwccardnum = rnd.Next(30000, 32000);
                }

                //personCreate(_per);

                _wkr.ID = _per.ID;
                //workerCreate(_wkr, SolutionDirectory() + "\\Machete.test\\jimmy_machete.jpg");
            }
            return true;
        }
开发者ID:kcbridges,项目名称:Machete,代码行数:20,代码来源:sharedUI.cs

示例10: GetFilteredInfo

        private void GetFilteredInfo(string start, string end, int id, IQueryable<Group> groups, DbSet<Classroom> classrooms, out IQueryable<Group> filteredGroups, out IQueryable<Classroom> filteredClassrooms)
        {
            DateTime startDt = Convert.ToDateTime(start);
            DateTime endDt = Convert.ToDateTime(end);
            //Find any overlapping events
            var overlapping = db.GroupInstances.
                                Where(period =>
                                    ((period.StartDateTime > startDt && period.EndDateTime < endDt)
                                    || (period.EndDateTime > startDt && period.EndDateTime < endDt)
                                    || (period.StartDateTime < startDt && period.EndDateTime > endDt)
                                    || (period.StartDateTime < startDt && period.EndDateTime > endDt))
                                    && period.GroupInstanceId != id).ToList();
            var overlappingGroups = overlapping.Select(x => x.GroupId).ToList();
            filteredGroups = groups.Where(x => !overlappingGroups.Contains(x.GroupId));

            var overlappingClassrooms = overlapping.Select(x => x.ClassroomId).ToList();
            filteredClassrooms = classrooms.Where(x => !overlappingClassrooms.Contains(x.ClassroomID));
        }
开发者ID:raskarov,项目名称:SchoolApp,代码行数:18,代码来源:GroupInstanceController.cs


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