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

  • 相关阅读:
    php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别
    手机web——自适应网页设计(html/css控制)
    js正则表达式语法
    禁止鼠标右键的代码(转)
    php获取文件名称和扩展名
    php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法
    js中cookie的使用详细分析
    fopen中r+和w+的区别
    左右选择框 js插件
    SpringMVC 过滤器Filter使用解析
  • 原文地址:https://www.cnblogs.com/thinkaspx/p/2637265.html
Copyright © 2011-2022 走看看