我有以下模型(注释定义给定对象中的字段)
public class ServiceModel
{
public List<ShippingRequest> ShippingRequest { get; set; }
public QuotesResult QuotesResult { get; set; }
}
public class ShippingRequest
{
public Address Address { get; private set; } // AddressId
public List<ShippingPackage> ShippingPackages { get; private set; }
}
public class ShippingPackage
{
public Package Package { get; private set; } // PackageId
public List<ShippingItem> ShippingItems { get; private set; } // IsSkipped
}
public class QuotesResult
{
public List<Quote> Quotes { get; set; } // PackageId, Cost
}
假设我有以下输入,我需要获取一个AddressId列表以及引用该地址的相应引号(通过PackageId)。此时已经填充了行情。
Quote.PackageId = Package.PackageId
INPUT:
假设我有以下三个ShippingRequests的输入
Address1 = {Package1, Package2, Package3}
Address2 = {Package5, Package8}
Address3 = {Package11, Package12}
要获取给定地址的所有报价,我需要加入 Package &#34; Package &#34;使用引用的 PackageId 。这样我就会知道这个Quote属于这个地址。
我试过这个但是我收到了一个错误:
var addrQuotes = ServiceModel.ShippingRequest
.GroupJoin(ServiceModel.QuotesResult.Quotes, c1 => c1.ShippingPackages
.SelectMany(y => y.Package.Id), c2 => c2.PackageId, (c1, c2) =>
new {
c1.Address.Id,
Quotes = c2.Select(e =>
{
e.Price = c1.ShippingPackages.Any(
x => x.ShippingItems.All(y => y.IsSkipped))
? 0
: e.Price + ExtraCost;
e.Provider = GetName(e.Code);
return e;
})
}).OrderBy(q => q.Id);
这是一个鱼子酱,我还需要检查包裹中的ShippingItems。如果ShippingPackage中的所有ShippingItem都有布尔标志&#34; IsSkipped&#34;设置为true,Quote的价格应该设置为0,否则为Quote.Price添加额外费用。
输出:
Address1 = [Quote1, Quote20, Quote21, Quote50, ...]
Address2 = [Quote3, Quote100...]
Address3 = [Quote5, Quote33, Quote12]
非常感谢任何帮助。
答案 0 :(得分:0)
我没有完成整个工作,但得到了一些编译和运行没有错误的东西。这应该让你指向正确的方向。
WHERE (TABLE1.A||'~~~'||TABLE1.B) NOT IN
(SELECT TABLE2.A||'~~~'||TABLE2.B FROM TABLE2)