Ejemplo n.º 1
0
        public void Solution12()
        {
            UserSearchCriteria criteria = new UserSearchCriteria
            {
                Country = "Poland"
            };

            using (var context = new RadioContext())
            {
                context.Database.Log += msg => WriteOutput(msg, ConsoleColor.Green);

                IQueryable <User> contacts = context.Contacts.OfType <User>();

                if (!string.IsNullOrEmpty(criteria.FirstName))
                {
                    contacts = contacts.Where(c => c.FirstName == criteria.FirstName);
                }

                if (!string.IsNullOrEmpty(criteria.LastName))
                {
                    contacts = contacts.Where(c => c.LastName == criteria.LastName);
                }

                if (!string.IsNullOrEmpty(criteria.Country))
                {
                    contacts = contacts.Where(c => c.Country == criteria.Country);
                }

                List <User> filteredUsers = contacts.Take(100).ToList();
            }
        }
Ejemplo n.º 2
0
        public void Example12()
        {
            UserSearchCriteria criteria = new UserSearchCriteria
            {
                Country = "Poland"
            };

            using (var context = new RadioContext())
            {
                context.Database.Log += msg => WriteOutput(msg, ConsoleColor.Blue);

                List <User> contacts = context.Contacts
                                       .OfType <User>()
                                       .Where(c => criteria.FirstName == null || c.FirstName == criteria.FirstName)
                                       .Where(c => criteria.LastName == null || c.LastName == criteria.LastName)
                                       .Where(c => criteria.Country == null || c.Country == criteria.Country)
                                       .Take(100)
                                       .ToList();
            }
        }