Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
SQL
SELECT [t0].[Id], 
       [t0].[Challan_No], 
       [t0].[Type], 
       [t0].[Measurement], 
       [t0].[Update_By], 
       [t0].[Date], 
       [t1].[Id] AS [Id2], 
       [t1].[Challan_No] AS [Challan_No2], 
       [t1].[Own_Comany], 
       [t1].[Parti_Name], 
       [t1].[Update_By] AS [Update_By2], 
       [t1].[Date] AS [Date2], 
       [t1].[IsDelete], 
       [t1].[Isgenbill], 
       [t2].[Rate] AS [Rate1]
FROM [dbo].[Challan_Total] AS [t0]
INNER JOIN [dbo].[Challan] AS [t1] ON [t0].[Challan_No] = [t1].[Challan_No]
INNER JOIN [dbo].[Rate] AS [t2] ON [t0].[Type] = [t2].[Meterial_type] 
                                AND [t1].Own_Comany = [t2].Company_Id 
                                AND [t1].Parti_Name=[t2].Parti_Id
WHERE [t0].[Challan_No] = '2014CH 10002'


I tried:
C#
var getch = dm.Challan_Totals
                      .Join(dm.Challans,
                      c => c.Challan_No, d => d.Challan_No,
                      (c, d) => new { c, d }).Select(b => b)
                      .Join(dm.Rates,
                      r => r.c.Type, s => s.Meterial_type &&
                      q => q.c., sq => sq.Meterial_type,
                      (r, s) => new { r, s.Rate1 })
                      .Where(m => m.r.c.Challan_No == "2014CH 10002");
Posted
Updated 6-Dec-14 5:21am
v2
Comments
Maciej Los 6-Dec-14 11:05am    
Do you mean Linq query?
mukesh mourya 6-Dec-14 11:07am    
yas Mr. Maciej Los
Maciej Los 6-Dec-14 11:09am    
What have you tried till now?
How does your entity model look?
What language: VB.NET, C#?
mukesh mourya 6-Dec-14 11:11am    
var getch = dm.Challan_Totals
.Join(dm.Challans,
c => c.Challan_No, d => d.Challan_No,
(c, d) => new { c, d }).Select(b => b)
.Join(dm.Rates,
r => r.c.Type, s => s.Meterial_type &&
q => q.c., sq => sq.Meterial_type,
(r, s) => new { r, s.Rate1 })
.Where(m => m.r.c.Challan_No == "2014CH 10002");
mukesh mourya 6-Dec-14 11:13am    
This code I tried in C#

You may use Linq2Sql's DataContext.GetCommand

C#
DbCommand dc = db.GetCommand(TheQeury);

Check out the msdn article on the method[^]

[added]
OR
See linqpad[^] (as suggested by Eliyahu in the thread above, I am not sure what the "lightweight" free version includes though...)
[\added]

Cheers,
C
 
Share this answer
 
v2
C#
var result = dm.Challan_Totals
                                          .Join(dm.Challans,
                                                ct => ct.Challan_No,
                                                c => c.Challan_No,
                                                (ct, c) => new { ct, c })
                                           .Join(dm.Rates,
                                                ctc => new
                                                {
                                                    Type = ctc.ct.Type,
                                                    Own_Company = ctc.c.Own_Comany,
                                                    Parti_Name = ctc.c.Parti_Name
                                                },
                                                rt => new
                                                {
                                                    Type = rt.Meterial_type,
                                                    Own_Company = rt.Company_Id,
                                                    Parti_Name = rt.Parti_Id
                                                },
                                                (ctc, rt) => new { ctc, rt })
                           .Where(x => x.ctc.ct.Challan_No == "2014CH 10002")
                                           .Select(res => new
                                           {
                                               Challan_no = res.ctc.ct.Challan_No,
                                               Type = res.ctc.ct.Type,
                                               Measurment = res.ctc.ct.Measurement,
                                               Rate1 = res.rt.Rate1,
                                               Amount = (res.ctc.ct.Measurement) * ((double)res.rt.Rate1)
                                           })
                                           .ToList();
 
Share this answer
 
v2
Comments
Maciej Los 11-Dec-14 10:28am    
Congratulations!
A 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900