我有两张有自己的slug的桌子。我想通过一个动作来比较slug来过滤帖子以便在用户看到视图。这是我的LINQ,但它没有用。
public ActionResult BaiViet(string slugCategory, string slugPost)
{
var model = db.Posts.Single(p => p.slug.Equals(slugPost)
&& p.catID.Equals(db.Categories.Single(c => c.slug.Equals(slugCategory)).catID)
);
return View(model);
}
我尝试了这个,但仍然没有工作:(
public ActionResult BaiViet(string slugCategory, string slugPost)
{
var model = (from c in db.Categories
from p in db.Posts
where c.catID == p.catID
&& c.slug == slugPost
&& p.slug == slugCategory
select p).FirstOrDefault();
}
答案 0 :(得分:1)
作者在原帖中发布的解决方案:
var model = (from p in db.Posts
join c in db.Categories
on p.catID equals c.catID
where
p.slugPost == slugbaiviet
&& c.slugCat == slugchuyenmuc
select p).FirstOrDefault();