zoukankan      html  css  js  c++  java
  • wordpress 复杂的表结构。。

    View Code
     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))

  • 相关阅读:
    上周热点回顾(11.2912.5)
    上周热点回顾(11.1511.21)
    上周热点回顾(11.2211.28)
    上周热点回顾(12.1312.19)
    Bambook程序达人赛报名公告
    HTML5技术专题上线啦!
    “博客无双,以文会友”活动公告
    上周热点回顾(12.612.12)
    [转]Java RMI之HelloWorld篇
    中国现代远程与继续教育网 统考 大学英语(B)考试大纲
  • 原文地址:https://www.cnblogs.com/thinkaspx/p/2637265.html
Copyright © 2011-2022 走看看