1

我有两个表,其中包含以下tb_Typestb_TypePrices

tb_Type
-------
id
title

tb_TypePrices
-------------
id
typeId
fromQuantity
ToQuantity
Supplier
Price 

这些表有父子关系

现在我想从tb_Typesjoin中获取数据tb_TypePriceswhere typeId=mytypeIdand parameterQuantityis NOT between fromQuantityand ToQuantity

4

3 回答 3

1
from t in tb_Type
join tp in tb_TypePrices on t.id equals tp.typeId
where t.id == mytypeId && 
      (parameterQuantity < tp.fromQuantity ||
       tp.ToQuantity < parameterQuantity)
select new { Type = t, TypePrice = tp }

或者,如果您想要一个对象中的所有过滤类型价格:

from t in tb_Type
join tp in tb_TypePrices on t.id equals tp.typeId into g
where t.id == mytypeId         
select new { 
    Type = t, 
    Prices = g.Where(x => parameterQuantity < x.fromQuantity ||
                          x.ToQuantity < parameterQuantity) 
}
于 2013-03-08T08:06:50.273 回答
0

假设您有外键关系,那么您应该可以使用

var query = tb_TypePrices
     .Where( t => t.fromQuantity < parameterQuantity || 
                  t.ToQuantity > parameterQuantity)
     .Select( t => new 
         { 
             t.fromQuantity, 
             t.ToQuantity,
             ... etc,
             Title=t.tb_Type.title 
         };
于 2013-03-08T09:05:20.583 回答
0

尝试这个 :

var data = from t1 in tb_Type
           join t2 in tb_TypePrices
           on t1.id equals t2.typeId
           where t2.fromQuantity < parameterQuantity || t2.ToQuantity > parameterQuantity
           select new { Type = t1, TypePrices = t2 };
于 2013-03-08T07:50:51.513 回答