For example, we want to query the names and ages of users in Shanghai who have made at least 3 purchases worth 10 bucks in the past 10 months from the user table customer and user order table orders. If it is written in the traditional way, I don't know how much code needs to be written, and various complex processing logic makes the semantics of the code very unclear. However, if it is written in LINQ, it will be as follows:

PHP中文网
Release: 2017-06-17 16:23:21
Original
1519 people have browsed it
var results = from customer in customers
              where customer.State == "WA"
              let custOrders = (from order in orders
                                where customer.ID == order.ID
                                select new { order.Date, order.Amount })
              where custOrders.Count(co => co.Amount >= 10 &&
                                     co.Date >= DateTime.Now.AddMonths(−10)) >= 3
              select new { customer.Name, customer.Age };<br><br>下面另附上一条分页的linq语句:<br>var productList=(from prod in db.Products<br>where prod.Type="零食" orderby prod.datatime select u).Skip(PageSize*(PageNum-1)).Take(PageSize);
Copy after login

The above is the detailed content of For example, we want to query the names and ages of users in Shanghai who have made at least 3 purchases worth 10 bucks in the past 10 months from the user table customer and user order table orders. If it is written in the traditional way, I don't know how much code needs to be written, and various complex processing logic makes the semantics of the code very unclear. However, if it is written in LINQ, it will be as follows:. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!