2

我需要在 C# 中对大型数据库执行 LINQ 查询。我需要在查询中使用的列之一是双列。我需要省略此列中小数点后 4 位以上的结果。数据库无法更改,因为其他程序需要使用它并使用我不想要的东西。然后将结果添加到列表中以供以后使用。我认为这会奏效。

where fun.Units != '*.?????*'

但是,它会返回字符文字中有太多字符的错误。到目前为止,整个查询看起来像这样

var clientQuery1 = from cli in main1.Clients
                   from pol in main1.Policies
                   from fun in main1.FundHoldings
                   from uni in main1.UnitPrices
                   where cli.AccountNumber == accNum
                   && pol.ClientRef == cli.ClientRef
                   && fun.FKeyRef == pol.PolicyRef
                   && uni.UnitPriceRef == fun.UnitPriceRef
                   && fun.Units != '*.?????*'
                   select uni.UnitName;
4

2 回答 2

1

Well you can solve that particular error using:

&& fun.Units != "*.?????*"

Note the change from single quotes to double quotes. However, that's not going to help you overall. What's the type of fun.Units in LINQ? If it's decimal, you might be able to use:

&& decimal.Round(fun.Units, 4) == fun.Units

... but it's not clear to me what that will do in the generated SQL. It's worth a try, but even if it works you should see what the SQL looks like.

于 2011-08-31T09:49:52.257 回答
1

您能否尝试使用以下查询并告诉我。

var clientQuery1 = from cli in main1.Clients
                   from pol in main1.Policies
                   from fun in main1.FundHoldings
                   from uni in main1.UnitPrices
                   where cli.AccountNumber == accNum
                   && pol.ClientRef == cli.ClientRef
                   && fun.FKeyRef == pol.PolicyRef
                   && uni.UnitPriceRef == fun.UnitPriceRef
                   && fun.Units == Math.Round(Convert.ToDouble(fun.Units),4)
                   select uni.UnitName;
于 2011-08-31T09:53:16.953 回答