如何查询linq lambda“where getdate() - Ngaynhap< 15”

时间:2013-06-26 13:21:49

标签: c# linq lambda

我对该查询有疑问:

    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);

1 个答案:

答案 0 :(得分: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);