Linq Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Linq Query

    Hello,

    I have two tables, Tags and ArticlesTags, with the following columns:

    Tags TagID, Text

    ArticlesTags TagID, ArticleID

    I need to create a LINQ query to select all records in Tags which are
    also in ArticlesTags. I have the following:

    Dim database As New CodeDataContext

    Dim tags = From t In database.Tags _
    Select t.TagID, t.Text _ ???

    How would I do this?

    Thanks,

    Miguel
  • Frans Bouma [C# MVP]

    #2
    Re: Linq Query

    shapper wrote:
    Hello,
    >
    I have two tables, Tags and ArticlesTags, with the following columns:
    >
    Tags TagID, Text
    >
    ArticlesTags TagID, ArticleID
    >
    I need to create a LINQ query to select all records in Tags which are
    also in ArticlesTags. I have the following:
    >
    Dim database As New CodeDataContext
    Dim tags = From t In database.Tags _
    Select t.TagID, t.Text _ ???
    >
    How would I do this?
    This is a C# newsgroup, so you'll get C# from me.

    A simple equi-join (INNER JOIN) will do:
    var tags = from t in database.Tags
    join at in database.Articl esTags on t.TagID
    equals at.ArticlesTags
    select t;

    FB

    --
    ------------------------------------------------------------------------
    Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
    LLBLGen Pro website: http://www.llblgen.com
    My .NET blog: http://weblogs.asp.net/fbouma
    Microsoft MVP (C#)
    ------------------------------------------------------------------------

    Comment

    Working...