Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Linq related tables

Linq related tables

Scheduled Pinned Locked Moved LINQ
csharpdatabasesql-serverlinqsysadmin
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eduard Keilholz
    wrote on last edited by
    #1

    Hey guys, I have a linq question. I'm pretty new to linq and having problems with the following : I have three MS SQL Server tables, which are related to eachother. Let's say the three tables are : [Objects] Object ID Object Name [ObjectProperties] Object ID Property ID [Properties] Property ID Property Name Now I want to be able to search for all objects for which a property 'x' is defined. In other words, I want to search through the properties table and find all properties which name match 'x' (it would be great to use a like statement). And then I want to return all objects for which that (one or more) properties are defined.

    .: I love it when a plan comes together :. http://www.zonderpunt.nl

    M 1 Reply Last reply
    0
    • E Eduard Keilholz

      Hey guys, I have a linq question. I'm pretty new to linq and having problems with the following : I have three MS SQL Server tables, which are related to eachother. Let's say the three tables are : [Objects] Object ID Object Name [ObjectProperties] Object ID Property ID [Properties] Property ID Property Name Now I want to be able to search for all objects for which a property 'x' is defined. In other words, I want to search through the properties table and find all properties which name match 'x' (it would be great to use a like statement). And then I want to return all objects for which that (one or more) properties are defined.

      .: I love it when a plan comes together :. http://www.zonderpunt.nl

      M Offline
      M Offline
      Michael Hildebrand
      wrote on last edited by
      #2

      Here is my shot at answering the question. Use 'where' statements (not joins), Linq to SQL optimizes the SQL output better... var query = from o in Objects from op in ObjectProperties from p in Properties where o.Object_ID == op.Object_ID where op.Property_ID == p.Property_ID where o.ObjectName.Contains(x) || p.PropertyName.Contains(x) orderby o.ObjectName, p.PropertyName select new { NameO = o.ObjectName, NameP=p.PropertyName };

      == // == BlueCoder

      E 1 Reply Last reply
      0
      • M Michael Hildebrand

        Here is my shot at answering the question. Use 'where' statements (not joins), Linq to SQL optimizes the SQL output better... var query = from o in Objects from op in ObjectProperties from p in Properties where o.Object_ID == op.Object_ID where op.Property_ID == p.Property_ID where o.ObjectName.Contains(x) || p.PropertyName.Contains(x) orderby o.ObjectName, p.PropertyName select new { NameO = o.ObjectName, NameP=p.PropertyName };

        == // == BlueCoder

        E Offline
        E Offline
        Eduard Keilholz
        wrote on last edited by
        #3

        That simple?? You for president!! Thanks!

        .: I love it when a plan comes together :. http://www.zonderpunt.nl

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups