how to get data from multiple table(more than 2 table) in linq to entity.

i ahve a 4 table as

1stockbyname
2.stocktrans
3.Mystock
4.product

Mystock
productid
qty


product
productid
productname


stockbyname
stockid
serviceid


stocktrans
stockid
price
amount

how to get data from multiple table(more than 2 table) in linq to entity.



well i want to fetch data from all four table on base of stock id,i tried it and found that
linq to entity work for only two table not for the multiple table,i dont know how to retrive data from multiple table,
could any expert let me know how i do it
nicemanishAsked:
Who is Participating?
 
vbNewbie2009Connect With a Mentor Commented:
from sn in db.Stockbyname
  from p in sn.stocktrans.product
  from ms in p.Product
select sn;

I found a decent reference for writing LINQ to Entities statements you might want to check out:
http://weblogs.asp.net/salimfayad/archive/2008/07/09/linq-to-entities-join-queries.aspx
0
 
vbNewbie2009Commented:
Do the stock ID fields in the last two tables relate directly to the product ID fields in the first two?  What is your primary relationship that logically relates all four tables?
0
 
nicemanishAuthor Commented:
sorry forget to add product id in product table.and stock id and product id are primary key.

Mystock
productid
qty


product
productid
productname


stockbyname
stockid
serviceid


stocktrans
stockid
price
amount
productid

see stockbyname  have a primary key stock id which is related to stoctrans-->stock id,through this stock id i will get product id from stocktrans.now from this product id i ahve to fetch quantity and product name from table mystock and product..

could you plese provide the way to write down query
0
 
nicemanishAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.