[C#]'ArrayLength' 的 LINQ 表达式节点类型不支持在 LINQ 到实体

标签: Linq C#
发布时间: 2017/2/27 4:20:52
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我已经实现了一个 linq 表达式来返回结果集,给出以下错误

{"LINQ 表达式节点类型 'ArrayLength' 不是支持 LINQ 到实体。"}

public IEnumerable<TBI.JV.Business.Objects.Asset> GetAssetsBasicBySedols(string[] sedols)
    {
        var priceDate = DateTime.UtcNow.Date.AddMonths(-8);
        var typeList = new string[]
            {
                "UNIT TRUST",
                "OEIC",
                "INVESTMENT TRUST",
                "INVESTMENT COMPANY",
                "PENSION FUND",
                "INSURANCE BOND",
                "LISTED EQUITY",
                "PREFERENCE SHARE",
                "ZERO DIVIDEND PREF",
                "GILT (CONVENTIONAL)",
                "GILT (INDEX LINKED)",
                "AIM",
                "VCT",
                "OFFSHORE FUND",
                "ETP"
            };
        using (var dealingContext = new dbDealingContainer())
        {
            return (from fundprice in dealingContext.FundPrices
                    where (fundprice.FUND_STATUS == "ACTIVE" || fundprice.FUND_STATUS == "SUSPENDED") &&
                          (fundprice.INVNAME != null || fundprice.INVNAME != "") &&
                          !fundprice.INVNAME.StartsWith("IFSL Bestinvest") &&
                        //  fundprice.WaterlooTradable == true &&
                           fundprice.BID_MID_PRICE > 0 && typeList.Contains(fundprice.FUND_TYPE)
                          && ((sedols.Length > 0 && sedols.Contains(fundprice.SEDOL_NUMBER)) 
                          ||sedols.Contains(fundprice.SEDOL_NUMBER_ACC)) || sedols.Length == 0
                    select new TBI.JV.Business.Objects.Asset
                    {
                        AssetName = fundprice.INVNAME,
                        AssetId = fundprice.Id,
                        AssetType = fundprice.FUND_TYPE,
                        Epic = fundprice.INVESTMENT_CODENAME,
                        StarRating = fundprice.STARLEN,
                        Sedol = fundprice.SEDOL_NUMBER,
                        SedolAcc = fundprice.SEDOL_NUMBER_ACC
                    }).ToList();
        }
    }

在下面这行代码谢多尔斯会引发错误。长度 > 0 和也谢多尔斯。长度 = = 0。如何解决此一问题。我的方法应该能够将空字符串数组作为输入,并返回所有记录。

解决方法 1:

定义两个变量上面查询和比改为在查询中使用它们︰

var isGreaterThanZero = sedols.Length > 0;
var isEmpty = sedols.Length == 0;
赞助商