日期:2014-05-20 浏览次数:20711 次
public List<News> GetCustomersWithOrders() { List<News> p = (from n in objDataContext.News where n.CID == n.NewsCatalog.CatalogID select new {类别=n.NewsCatalog.CatalogName,标题=n.NewsTitle,日期=n.NewsDate }).ToList(); return p; }
public List<News> GetCustomersWithOrders() { List<News> p = (from n in objDataContext.News from c in objDataContext.Catalog where n.CID == c.CatalogID select new News(){类别=n.NewsCatalog.CatalogName,标题=n.NewsTitle,日期=n.NewsDate }).ToList(); return p; }
------解决方案--------------------
LINQ使用JOIN
var q =
from e in db.Employees
join o in db.Books on e.EmployeeID equals o.EmployeeID into b
from x in b.DefaultIfEmpty()
select new
{
e.ID,
e.Name,
o.BookName
};
------解决方案--------------------