views:

68

answers:

1

I have a list<> of phone numbers and I am trying to join that with the corresponding records in the db table and get an order number and a customer ID. Also the list has the whole number as one string and the DB has it broken to area code, prefix, number each as separate fields.

I am fairly new to LINQ, so this is a beyond what I currently know. Any suggestions are GREATLY appreciated.

var tnbrs = new List<string>();

have tried:

    var tntable = tnbrs.Cast<DataSet>();  

    var tntable = tnbrs.AsQueryble();<code>

    var custdata = from c in db.CUSTs  
               join t in tntable on c.NPA + c.NXX + c.LINE_NBR equals t.???  
               select new { c.PON, c.PartnerID };
+1  A: 

You dont have to cast tnbrs to dataset try this instead

var custdata = from c in db.CUSTs  
               where tnbrs.Contains(c.NPA + c.NXX + c.LINE_NBR)
               select new { c.PON, c.PartnerID };

It generates sql query something like this

SELECT [t0].[PON], [t0].[PartnerID]
FROM [dbo].[CUSTs  ] AS [t0]
WHERE [t0].[NPA]) + [t0].[Nxx] + [t0].[LINE_NBR] IN (@p0, @p1)

Cheers

Ramesh Vel
Ramesh...thank you! This is working.
Pete
Am glad it helped.. :)
Ramesh Vel
I'm having an issue with this now. Im getting a SQL error saying error near 0. After using a Linq to SQL visualizer, the problem is when Visual Studio is assigning the numbers in the list to the parameters. It will assign the first 10 just fine, but once it hit the 11th, it jumps to the number in at index 1 and assigns the same number 10 times to different params, but adding a last digit(0-9) to make each one unique, it then moves to the number at index 2 and proceeds to assign that same number multiple times, it actually runs to the the end of the params. What is going on here?
Pete
So apparently its the LINQ to SQL visualizer, procured from Scott Gu's blog, that has the problems with assigning the parameters correctly.
Pete
Oh am not aware of that, could you share a link... i ll take a look into that...
Ramesh Vel
Ramesh, sorry I didnt get notified that you responded to my last comment, anyway here is the link http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
Pete