Linq related tables
-
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
-
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
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
-
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
That simple?? You for president!! Thanks!
.: I love it when a plan comes together :. http://www.zonderpunt.nl