我对该查询有疑问:
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);
答案 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);