LINQ加入在分句间分句、LINQ

2023-09-03 07:49:04 作者:今晚注定无梦°

我有一些问题,拼凑一个LINQ查询,将加入基于一个zip code表。我需要加入基于表客户的拉链code是否在于在由ZIPBEG和ZIPEND列确定的范围内拉链codeS的。

在T-SQL会是这个样子:

 加入[邮编codeTable] [拉链]
    ON [客户] [拉链code]之间的[拉链]。[ZIPBEG]和[拉链]。[ZIPEND]

 -  要么

JOIN [邮编codeTable] [拉链]
    ON [拉链] [ZIPBEG]< = [客户] [拉链code]
        和[拉链] [ZIPEND] GT; = [客户] [拉链code]
 

解决方案

您不能专门参加在这种情况下,只有同类产品中加入所offically支持是建立在平等,这你在T-SQL的条件没有按T符合。

相反,你将必须执行一个笛卡尔积,然后筛选合适的条件:

 从C在顾客
从ž在拉链
哪里
  z.ZipBeg< = c.Zip code和;&安培; c.Zip $ C $℃下= z.ZipEnd
选择
  C
 
LINQ数据库访问技术

I am having some issues throwing together a LINQ query that will join a table based on a zip code. I need to join the table based on whether the customer's zip code lies with in a range of zip codes that is determined by ZIPBEG and ZIPEND columns.

The T-SQL would look something like this:

JOIN [ZipCodeTable] [zips] 
    ON [customer].[zipcode] BETWEEN [zips].[ZIPBEG] AND [zips].[ZIPEND]

-- or

JOIN [ZipCodeTable] [zips] 
    ON [zips].[ZIPBEG] <= [customer].[zipcode] 
        AND [zips].[ZIPEND] >= [customer].[zipcode]

解决方案

You can't specifically join on this condition, the only kind of join that is offically supported is one based on equality, which your condition in T-SQL doesn't conform to.

Instead, you will have to perform a cartesian product and then filter on the appropriate conditions:

from c in customers
from z in zips
where
  z.ZipBeg <= c.ZipCode && c.ZipCode <= z.ZipEnd
select
  c