linq join statement help reqd
-
I am trying to do a join using linq. i have 2 tables oempart and parttypes. i want to carry out join in linq and select only rows where oempart.id=5; my sql select statement is : (sql statement works fine) Select oemparts.name,parttypes.id,parttypes.product_type from oemparts join parttypes on oemparts.parttype_id=parttypes.id where parttypes.id =5 i want to do same with linq. i tried alot but can't do it. Please help... Question 2: Also this application has been developed partly by other programmer who had very good idea of linq. As i see, his sql to linq file (dbml) has a lot of coding... eg [table(name="dbo.oemparts")] and then 100 lines of code, similar case for associations etc... I want to know if such code is hardcoded or is produced by vs2008. i tried making linq to sql file from scratch but didn't have this code... is there any designer way of doin it or is it hard coding... Thanx
haseeb
-
I am trying to do a join using linq. i have 2 tables oempart and parttypes. i want to carry out join in linq and select only rows where oempart.id=5; my sql select statement is : (sql statement works fine) Select oemparts.name,parttypes.id,parttypes.product_type from oemparts join parttypes on oemparts.parttype_id=parttypes.id where parttypes.id =5 i want to do same with linq. i tried alot but can't do it. Please help... Question 2: Also this application has been developed partly by other programmer who had very good idea of linq. As i see, his sql to linq file (dbml) has a lot of coding... eg [table(name="dbo.oemparts")] and then 100 lines of code, similar case for associations etc... I want to know if such code is hardcoded or is produced by vs2008. i tried making linq to sql file from scratch but didn't have this code... is there any designer way of doin it or is it hard coding... Thanx
haseeb
Hi, some resources about joins: http://www.onedotnetway.com/linq-to-sql-join-on-multiple-conditions/[^] http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx[^] All that coding you see is generated by linq to sql designer when you add new entities.
-
Hi, some resources about joins: http://www.onedotnetway.com/linq-to-sql-join-on-multiple-conditions/[^] http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx[^] All that coding you see is generated by linq to sql designer when you add new entities.
Thanx... I am sorry that i am asking alot of questions. actually, i am assigned a project in the middle. Original person has left and hasn't left any piece of documentation. He has used linq extensively in 2 forms with incomplete functionality and i want to learn linq . Already, i am doin alot of searching and learning on linq but as i mentioned, in dbml file, there is alot of code (designtime generated) and i want to learn doing this.. .i made a new linqto sql class, added tables by dragging them , some code is generated but entities are not generated. how do i generate these entities... Thanks for ur replies. They all have been very useful. also in links that you have forwarded , linq syntax used is var a = from b in db.TableName do something... i have tried this...it doesn't work, when i try like var a = from b in db.gettable do something... it works... what's the concept behind this... Thankyou for helping
haseeb
-
Thanx... I am sorry that i am asking alot of questions. actually, i am assigned a project in the middle. Original person has left and hasn't left any piece of documentation. He has used linq extensively in 2 forms with incomplete functionality and i want to learn linq . Already, i am doin alot of searching and learning on linq but as i mentioned, in dbml file, there is alot of code (designtime generated) and i want to learn doing this.. .i made a new linqto sql class, added tables by dragging them , some code is generated but entities are not generated. how do i generate these entities... Thanks for ur replies. They all have been very useful. also in links that you have forwarded , linq syntax used is var a = from b in db.TableName do something... i have tried this...it doesn't work, when i try like var a = from b in db.gettable do something... it works... what's the concept behind this... Thankyou for helping
haseeb
var a = from b in db.TableName first, you have the databasecontext (db) in this example, inside db are the entities you have drag and drop from your database. With that line of code you are basically doing: select * from tableName but without write any sql code neither using datasets or similar... check the other developers sintax, post an example here...
-
I am trying to do a join using linq. i have 2 tables oempart and parttypes. i want to carry out join in linq and select only rows where oempart.id=5; my sql select statement is : (sql statement works fine) Select oemparts.name,parttypes.id,parttypes.product_type from oemparts join parttypes on oemparts.parttype_id=parttypes.id where parttypes.id =5 i want to do same with linq. i tried alot but can't do it. Please help... Question 2: Also this application has been developed partly by other programmer who had very good idea of linq. As i see, his sql to linq file (dbml) has a lot of coding... eg [table(name="dbo.oemparts")] and then 100 lines of code, similar case for associations etc... I want to know if such code is hardcoded or is produced by vs2008. i tried making linq to sql file from scratch but didn't have this code... is there any designer way of doin it or is it hard coding... Thanx
haseeb
didn't the blog http://openreferals.com/blogs/post/How-to-use-LINQ.aspx[^] helped you. You can write up comment there also if you want direct help from me. you can try something like var x = from x in (from person in Accounts join p in AccountPermissions on person.AccountID equals p.AccountID select new { userID = person.AccountID, per = p.PermissionID} ) where x.AccountID == 5 select x;
-
I am trying to do a join using linq. i have 2 tables oempart and parttypes. i want to carry out join in linq and select only rows where oempart.id=5; my sql select statement is : (sql statement works fine) Select oemparts.name,parttypes.id,parttypes.product_type from oemparts join parttypes on oemparts.parttype_id=parttypes.id where parttypes.id =5 i want to do same with linq. i tried alot but can't do it. Please help... Question 2: Also this application has been developed partly by other programmer who had very good idea of linq. As i see, his sql to linq file (dbml) has a lot of coding... eg [table(name="dbo.oemparts")] and then 100 lines of code, similar case for associations etc... I want to know if such code is hardcoded or is produced by vs2008. i tried making linq to sql file from scratch but didn't have this code... is there any designer way of doin it or is it hard coding... Thanx
haseeb