问题 你想用LINQ写一个搜索查询,能被转换成更有效率的SQL.另外,你想用EF的CodeFirst方式实现. 解决方案 假设你有如下Figure 13-6所示的模型 Figure 13-6. A simple model with a Reservation entity 首先,这个例子用EF的CodeFirst方式实现,在Listing 13-10,我们创建实体类
这个类是真正的数据库操作类。上面的那个类仅仅是调用了这个封装类的方法进行的操作 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data.Entity;
using System.Data.Linq;
using Sy