<small id='R1Vvz'></small><noframes id='R1Vvz'>

    <legend id='R1Vvz'><style id='R1Vvz'><dir id='R1Vvz'><q id='R1Vvz'></q></dir></style></legend>

      • <bdo id='R1Vvz'></bdo><ul id='R1Vvz'></ul>

      1. <i id='R1Vvz'><tr id='R1Vvz'><dt id='R1Vvz'><q id='R1Vvz'><span id='R1Vvz'><b id='R1Vvz'><form id='R1Vvz'><ins id='R1Vvz'></ins><ul id='R1Vvz'></ul><sub id='R1Vvz'></sub></form><legend id='R1Vvz'></legend><bdo id='R1Vvz'><pre id='R1Vvz'><center id='R1Vvz'></center></pre></bdo></b><th id='R1Vvz'></th></span></q></dt></tr></i><div id='R1Vvz'><tfoot id='R1Vvz'></tfoot><dl id='R1Vvz'><fieldset id='R1Vvz'></fieldset></dl></div>
        <tfoot id='R1Vvz'></tfoot>

        标签系统的 linq 查询 - 搜索多个标签

        linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)
          <bdo id='4Tr9H'></bdo><ul id='4Tr9H'></ul>
          <i id='4Tr9H'><tr id='4Tr9H'><dt id='4Tr9H'><q id='4Tr9H'><span id='4Tr9H'><b id='4Tr9H'><form id='4Tr9H'><ins id='4Tr9H'></ins><ul id='4Tr9H'></ul><sub id='4Tr9H'></sub></form><legend id='4Tr9H'></legend><bdo id='4Tr9H'><pre id='4Tr9H'><center id='4Tr9H'></center></pre></bdo></b><th id='4Tr9H'></th></span></q></dt></tr></i><div id='4Tr9H'><tfoot id='4Tr9H'></tfoot><dl id='4Tr9H'><fieldset id='4Tr9H'></fieldset></dl></div>
          <legend id='4Tr9H'><style id='4Tr9H'><dir id='4Tr9H'><q id='4Tr9H'></q></dir></style></legend>

          <small id='4Tr9H'></small><noframes id='4Tr9H'>

          • <tfoot id='4Tr9H'></tfoot>

                    <tbody id='4Tr9H'></tbody>
                  本文介绍了标签系统的 linq 查询 - 搜索多个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两张表,Tags(tagid, postid, tagname) 和 posts(postid, name, ...)
                  现在我想做一个查询,返回所有具有通用标签数量的帖子.比如:我想要所有带有标签 asp.net 和 jquery 的帖子

                  正如我所说,要查找的标签数量是通用的

                  我该怎么做?

                  谢谢

                  2009 年 11 月 17 日更新:有一个问题:表之间的关系不存在,因为我的主键在 2 个字段上(用于版本控制)我怎样才能使它没有关系?我正在使用 Linq To 实体

                  此外,查询应该具有良好的性能,并且不应发出数千个服务器请求.

                  解决方案

                  我猜你不能在我遇到问题的 EF 3.5 中使用 .Contains().我通过使用这个WhereIn"扩展解决了这个问题

                  'Contains()' 使用 Linq to Entities 解决方法?p>

                  把它放到一个静态类中,然后你可以使用类似的东西:

                  IQueryablePostsWithByTags(IEnumerable<string> tagNames){var postIds = context.Tags.Select(t=>t.postid);foreach(tagNames 中的 var 标记){postIds = context.Tags.WhereIn(t=> t.postid, postIds).Where(t=>t.tagname == tag);}返回 context.Tags.Where(t=> t.posId, postIds)}

                  我真的认为你应该看看你的表之间的关系.

                  I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...)
                  now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have the tag asp.net AND jquery

                  as i said, the amount of tags to look for is generic

                  how can i do something like that?

                  thx

                  update 17.11.2009: there is one problem: the relation betwenn the tables does not exist, because my primary key is on 2 fields (for versioning) how can i make it without a relation? Im using Linq To Entities

                  also, the query should have good performance, and should not make thousands of server requests.

                  解决方案

                  I guess you can't use .Contains() using EF 3.5 which I have had a problem with. I got around this by using this "WhereIn" extension

                  'Contains()' workaround using Linq to Entities?

                  put this into a static class then you could use something like:

                  IQueryable<Post> PostsWithByTags(IEnumerable<string> tagNames)
                  {
                      var postIds = context.Tags.Select(t=>t.postid); 
                  
                      foreach (var tag in tagNames)
                      {
                         postIds = context.Tags
                                       .WhereIn(t=> t.postid, postIds)
                                       .Where(t=>t.tagname == tag);
                      }
                  
                      return context.Tags.Where( t=> t.posId, postIds)
                  }
                  

                  I really think you should look at having relationships between your tables though.

                  这篇关于标签系统的 linq 查询 - 搜索多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Wrap a delegate in an IEqualityComparer(在 IEqualityComparer 中包装委托)
                  C#: Altering values for every item in an array(C#:更改数组中每个项目的值)
                  What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)
                  Cannot convert lambda expression to type #39;object#39; because it is not a delegate type(无法将 lambda 表达式转换为类型“对象,因为它不是委托类型)
                  What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)
                  Replacing Some Elements in XML [Sample XML Provided](替换 XML 中的一些元素 [提供 XML 示例])

                    <bdo id='2lkmy'></bdo><ul id='2lkmy'></ul>

                    <small id='2lkmy'></small><noframes id='2lkmy'>

                  • <tfoot id='2lkmy'></tfoot>
                      <i id='2lkmy'><tr id='2lkmy'><dt id='2lkmy'><q id='2lkmy'><span id='2lkmy'><b id='2lkmy'><form id='2lkmy'><ins id='2lkmy'></ins><ul id='2lkmy'></ul><sub id='2lkmy'></sub></form><legend id='2lkmy'></legend><bdo id='2lkmy'><pre id='2lkmy'><center id='2lkmy'></center></pre></bdo></b><th id='2lkmy'></th></span></q></dt></tr></i><div id='2lkmy'><tfoot id='2lkmy'></tfoot><dl id='2lkmy'><fieldset id='2lkmy'></fieldset></dl></div>
                        1. <legend id='2lkmy'><style id='2lkmy'><dir id='2lkmy'><q id='2lkmy'></q></dir></style></legend>
                            <tbody id='2lkmy'></tbody>