Exemple #1
0
        public void DifferenceTest()//返回指示两个字符表达式的 SOUNDEX 值之差的整数值。
        {
            using (var edm = new NorthwindEntities())
            {
                var cust1 = from e in edm.Order_Details
                            //select SqlFunctions.Difference("zxm","zxm");
                            select SqlFunctions.Difference("1234", "123");

                //DIFFERENCE(N'zxm', N'zxm') AS [C1]
                //DIFFERENCE(N'1234', N'123') AS [C1]
                cust1.TraceSql();
                Console.WriteLine(cust1.First());//4
            }
        }
Exemple #2
0
        public List <Customer> SearchCustomersByName(string term)
        {
            if (term == null)
            {
                return(null);
            }

            var customers = new List <Customer>();

            customers.AddRange(
                _context.Customers
                .Where(c =>
                       SqlFunctions.PatIndex("%" + term + "%", c.FirstName) > 0 ||
                       SqlFunctions.PatIndex("%" + term + "%", c.LastName) > 0 ||
                       SqlFunctions.SoundCode(c.FirstName).Contains(SqlFunctions.SoundCode(term)) ||
                       SqlFunctions.SoundCode(c.LastName).Contains(SqlFunctions.SoundCode(term)))
                .Take(40).ToList());

            customers.AddRange(_context.Customers.OrderByDescending(c => SqlFunctions.Difference(c.LastName, term)).Take(40).ToList());

            return(customers);
        }