-3

我对该查询有疑问:

    select SanPham.*,TenSX  
    from SanPham join NhaSanXuat on SanPham.MaSX = NhaSanXuat.MaSX 
    where GETDATE()- NgayNhap < 15
    order by NgayNhap,MaSP desc

我似乎有一个问题:where getdate() - Ngaynhap < 15

这是 linq 查询:

var sp = db.SanPhams.Join(db.NhaSanXuats, masp => masp.MaSX, mansx => mansx.MaSX, 
(masp, mansx) => new { SanPham = masp, NhaSanXuat = mansx })
.Where(ngaynhap=>DateTime.Now.Day - db.SanPhams.Select(n=>n.NgayNhap.Value.Day))
.OrderByDescending(nhap => nhap.SanPham.NgayNhap)
.ThenByDescending(masp => masp.SanPham.MaSP)
.Select(s => s.SanPham);
4

1 回答 1

0

如果没有更多信息,就很难更好地帮助您。但我认为您正在寻找以下内容:

var sp = db.SanPhams.Join(db.NhaSanXuats, masp => masp.MaSX, mansx => mansx.MaSX, 
(masp, mansx) => new { SanPham = masp, NhaSanXuat = mansx })
.Where(db => (DateTime.Now - db.SanPham.NgayNhap).Days < 15)
.OrderByDescending(nhap => nhap.SanPham.NgayNhap)
.ThenByDescending(masp => masp.SanPham.MaSP)
.Select(s => s.SanPham);
于 2013-06-26T13:38:35.337 回答