?
Solved

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

Posted on 2011-04-28
4
Medium Priority
?
351 Views
Last Modified: 2013-11-11
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
0
Comment
Question by:nicemanish
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:vbNewbie2009
ID: 35488173
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
 

Author Comment

by:nicemanish
ID: 35488514
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
 
LVL 1

Accepted Solution

by:
vbNewbie2009 earned 1500 total points
ID: 35490052
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
 

Author Closing Comment

by:nicemanish
ID: 35799668
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question