开发者

Cannot access Table in converted query (plain SQL to LINQ)

I'm trying to convert this worki开发者_StackOverflowng 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());


var q =
  from cos in oc.cosmetics
  join com in oc.company on cos.company_id equals com.company_id
  where cos.date >= DateTime.Now
     && cos.male_female == "female"
     && cos.category == "cosmetics_perfumes"
  orderby cos.brand, cos.product, cos.size, cos.price
  select new { cos, com.company_site };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜