wordpress 复杂的表结构。。

public class Post { public int ID { get; set; } public User author { get; set; } public DateTime post_date { get; set; } public DateTime post_date_gmt { get; set; } public string post_content { get; set; } public string post_title { get; set; } public string post_status { get; set; } public string comment_status { get; set; } public string ping_status { get; set; } public string post_password { get; set; } public string post_name { get; set; } public string to_ping { get; set; } public string pinged { get; set; } public DateTime post_modified { get; set; } public DateTime post_modified_gmt { get; set; } public string post_content_filtered { get; set; } public int post_parent { get; set; } public string guid { get; set; } public int menu_order { get; set; } public string post_type { get; set; } public string post_mime_type { get; set; } public int comment_count { get; set; } public List<Term_relationships> Term_relationships { get; set; } } public class Term { public int id { get; set; } public string name { get; set; } public string slug { get; set; } public int term_group { get; set; } //public virtual ICollection<Term_taxonomy> termList { get; set; } } public class Term_taxonomy { public int id { get; set; } public virtual Term term { get; set; } public string taxonomy { get; set; } public string description { get; set; } public int parent { get; set; } public int count { get; set; } public virtual ICollection<Term_taxonomy> relationships { get; set; } } public class Term_relationships { public int id { get; set; } public Post post { get; set; } public Term_taxonomy term_taxonomy { get; set; } public int term_order { get; set; } public virtual ICollection<Term_taxonomy> taxonomys { get; set; } }
用EF实现查询
根据 分类查询 文章
错误的
var posts = DataContext.Posts. Include(p => p.Term_relationships.Select(qs => qs.term_taxonomy).Select(pas => pas.term).Where(psss => psss.slug == cat));
这样是可以关联出数据来 可是隐藏的太深了
var term = DataContext.Terms.Where(p => p.slug == cat) .Include(x=>x.termList.Select(s=>s.relationships.Select(p=>p.post)));
最终想得到的数据(缺少where)
PagedList<Post> orders = DataContext.Posts.Include("Term_relationships") .Include("Term_relationships.term_taxonomy") .Include("Term_relationships.term_taxonomy.term") .OrderBy(p => p.post_date) .ToPagedList(id ?? 1, 5);
//高手给出的解决方案!
.Where(x => x.Term_relationships.Select(r => r.term_taxonomy.term.slug).Contains(cat))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?