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

  • 相关阅读:
    撕衣服的简易实现
    简易的画画板的实现
    图片简易处理
    在内存中创建原图的副本
    缩放图片并加载到内存中
    加载大图片的OOM异常
    计算机表示图形的形式
    虚拟短信
    ContentProvider 共享数据
    内容观察者
  • 原文地址:https://www.cnblogs.com/thinkaspx/p/2637265.html
Copyright © 2011-2022 走看看