How to compare List<String> to DB Table using LINQ

痴心易碎 提交于 2019-12-04 05:18:23

问题


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:


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)


来源:https://stackoverflow.com/questions/3922619/how-to-compare-liststring-to-db-table-using-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!