LINQ to Entities不支持LINQ表达式节点类型'ArrayLength'

时间:2015-05-07 13:33:34

标签: c# linq

我已经实现了一个linq表达式来返回结果集并得到以下错误

{“LINQ to Entities不支持LINQ表达式节点类型'ArrayLength'。”}

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();
        }
    }

在以下代码行中抛出错误sedols.Length&gt; 0和sedols.Length == 0.我该如何解决这个问题。我的方法应该能够将一个空字符串数组作为输入并返回所有记录。

2 个答案:

答案 0 :(得分:9)

在查询上方定义两个变量,而不是在查询中使用它们:

var isGreaterThanZero = sedols.Length > 0;
var isEmpty = sedols.Length == 0;

答案 1 :(得分:2)

LINQ to Entities支持select housing_id, category, visits from ( select housing_id, category, visits, @category_rank := if(@current_category = category, @category_rank + 1, if(@current_category := category, 1, 1) ) as category_rank from visit_counts, (select @category_rank := 0, @current_category := null) t2 order by category, visits desc ) ranked where category_rank <= 3; 扩展方法。

使用Any()exampleArray.Any()意味着您不必声明局部变量,幸运的是它是一个很好的,简洁的语法。