LINQ - Select records

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

    #1

    LINQ - Select records

    Hello,

    I have 3 SQL tables:

    [Tags] TagId, TagText
    [Posts] PostId, TagId, ...
    [Files] FileId, TagId, ...

    I need to, using LINQ, select all records in Tags, including the
    columns TagId and TagText, but adding a new column of type boolean
    which is True if the tag is associated to a Post OR to a File, i.e.,
    if the TagId exists in Posts or Files.

    How can I do this?

    Thanks,
    Miguel

  • Ralf Rottmann

    #2
    Re: LINQ - Select records

    Miguel,

    Have you used the new O/RM tool within Visual Studio 2008 to create the db
    context?

    You should then be able to express:

    var query = from t in db.Tags
    select new
    {
    TagId = t.TagId,
    TagText = t.TagText,
    hasPosts = t.Posts 0,
    hasFiles = t.Files 0
    };

    This is supposed to work because LINQ to SQL exposes the foreign key
    relationship as a collection at the object level.

    Please lest me/us know how it goes!

    Best regards
    -Ralf

    Spezialisiert auf Smart Building Integration, die Vernetzung von Gebäude- und Medientechnik, High-End Multiroom Audio/Video, professionelle Licht- und Beschallungssysteme sowie leistungsfähige Datennetzwerke für Hospitality, Gewerbe und Premium-Residential-Projekte.



    "shapper" <mdmoura@gmail. comwrote in message
    news:1194483064 .672094.123880@ o3g2000hsb.goog legroups.com...
    Hello,
    >
    I have 3 SQL tables:
    >
    [Tags] TagId, TagText
    [Posts] PostId, TagId, ...
    [Files] FileId, TagId, ...
    >
    I need to, using LINQ, select all records in Tags, including the
    columns TagId and TagText, but adding a new column of type boolean
    which is True if the tag is associated to a Post OR to a File, i.e.,
    if the TagId exists in Posts or Files.
    >
    How can I do this?
    >
    Thanks,
    Miguel
    >

    Comment

    • Ralf Rottmann \(www.24100.net\)

      #3
      Re: LINQ - Select records

      Did it work? Any feedback?


      "Ralf Rottmann" <BeSharp@live.c omwrote in message
      news:BD0B1514-2ED6-42AE-8CF7-7DECBE12F413@mi crosoft.com...
      Miguel,
      >
      Have you used the new O/RM tool within Visual Studio 2008 to create the db
      context?
      >
      You should then be able to express:
      >
      var query = from t in db.Tags
      select new
      {
      TagId = t.TagId,
      TagText = t.TagText,
      hasPosts = t.Posts 0,
      hasFiles = t.Files 0
      };
      >
      This is supposed to work because LINQ to SQL exposes the foreign key
      relationship as a collection at the object level.
      >
      Please lest me/us know how it goes!
      >
      Best regards
      -Ralf
      >
      Spezialisiert auf Smart Building Integration, die Vernetzung von Gebäude- und Medientechnik, High-End Multiroom Audio/Video, professionelle Licht- und Beschallungssysteme sowie leistungsfähige Datennetzwerke für Hospitality, Gewerbe und Premium-Residential-Projekte.

      >
      >
      "shapper" <mdmoura@gmail. comwrote in message
      news:1194483064 .672094.123880@ o3g2000hsb.goog legroups.com...
      >Hello,
      >>
      >I have 3 SQL tables:
      >>
      >[Tags] TagId, TagText
      >[Posts] PostId, TagId, ...
      >[Files] FileId, TagId, ...
      >>
      >I need to, using LINQ, select all records in Tags, including the
      >columns TagId and TagText, but adding a new column of type boolean
      >which is True if the tag is associated to a Post OR to a File, i.e.,
      >if the TagId exists in Posts or Files.
      >>
      >How can I do this?
      >>
      >Thanks,
      >Miguel
      >>

      Comment

      • shapper

        #4
        Re: LINQ - Select records

        On Nov 9, 2:50 pm, "Ralf Rottmann \(www.24100.net \)"
        <BeSh...@live.c omwrote:
        Did it work? Any feedback?
        >
        "Ralf Rottmann" <BeSh...@live.c omwrote in message
        >
        news:BD0B1514-2ED6-42AE-8CF7-7DECBE12F413@mi crosoft.com...
        >
        Miguel,
        >
        Have you used the new O/RM tool within Visual Studio 2008 to create the db
        context?
        >
        You should then be able to express:
        >
        var query = from t in db.Tags
        select new
        {
        TagId = t.TagId,
        TagText = t.TagText,
        hasPosts = t.Posts 0,
        hasFiles = t.Files 0
        };
        >
        This is supposed to work because LINQ to SQL exposes the foreign key
        relationship as a collection at the object level.
        >
        Please lest me/us know how it goes!
        >
        Best regards
        -Ralf
        >>
        "shapper" <mdmo...@gmail. comwrote in message
        news:1194483064 .672094.123880@ o3g2000hsb.goog legroups.com...
        Hello,
        >
        I have 3 SQL tables:
        >
        [Tags] TagId, TagText
        [Posts] PostId, TagId, ...
        [Files] FileId, TagId, ...
        >
        I need to, using LINQ, select all records in Tags, including the
        columns TagId and TagText, but adding a new column of type boolean
        which is True if the tag is associated to a Post OR to a File, i.e.,
        if the TagId exists in Posts or Files.
        >
        How can I do this?
        >
        Thanks,
        Miguel
        Hello,

        Sorry, I was out of work. I didn't try it yet.

        I was trying to put this in a LINQ Data Source.

        This is something I am not sure. Is it possible to use any LINQ query
        in a LINQ Data Source?

        Thanks,
        Miguel

        Comment

        Working...