无法访问转换后的查询中的表(普通 SQL 到 LINQ)
我正在尝试将此有效的 SQL 查询转换为 LINQ 查询 (EF),
但在 LINQ 查询中我无法进入类别数据表。 这是我正在运行的 SQL 查询:
SELECT cosmetics.brand, cosmetics.product, cosmetics.size, cosmetics.price, cosmetics.sale_type, cosmetics.description, cosmetics.date, cosmetics.company_id, cosmetics.category, cosmetics.[male-female], company.company_site
FROM cosmetics INNER JOIN company ON cosmetics.company_id = company.company_id
WHERE (cosmetics.date >= GETDATE())
AND (cosmetics.[male-female] = N'female')
AND (cosmetics.category = N'cosmetics_perfumes')
ORDER BY cosmetics.brand, cosmetics.product, cosmetics.size, cosmetics.price"
运行良好:
var female = (from c in db.cosmetics
.Where(v => v.date > DateTime.Now)
.Where(d => d.male_female == "female")
.Include("company")
select c);
return View(female.ToList());
I'm trying to convert this working SQL query into a LINQ query (EF)
But in the LINQ query I can't get into the category data table.
This is my working SQL Query:
SELECT cosmetics.brand, cosmetics.product, cosmetics.size, cosmetics.price, cosmetics.sale_type, cosmetics.description, cosmetics.date, cosmetics.company_id, cosmetics.category, cosmetics.[male-female], company.company_site
FROM cosmetics INNER JOIN company ON cosmetics.company_id = company.company_id
WHERE (cosmetics.date >= GETDATE())
AND (cosmetics.[male-female] = N'female')
AND (cosmetics.category = N'cosmetics_perfumes')
ORDER BY cosmetics.brand, cosmetics.product, cosmetics.size, cosmetics.price"
This is working just fine:
var female = (from c in db.cosmetics
.Where(v => v.date > DateTime.Now)
.Where(d => d.male_female == "female")
.Include("company")
select c);
return View(female.ToList());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)