LINQ to Entities不支持LINQ表达式节点类型“NewArrayBounds”

时间:2017-05-08 19:52:03

标签: c# arrays entity-framework linq linq-to-entities

 select new ProviderMeta
            {
                LoginId = user.LoginId,
                AgencyId = user.AgencyId,
                Application = user.Application,
                UserId = user.UserId,
                Name = agencySnapshot.Name,
                Roles = new int[0],
                Cluster = app.ClusterId ?? 0,
                Created = app.Created,
                TitleType = user.TitleType,
                Feature = (foundFeature == null ? 0 : foundFeature.Feature)
            }).ToList();

这里,Roles是一个整数数组,但它不允许我分配一个空数组   零。   帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

在类的空构造函数中初始化数组:

public class ProviderMeta
{
    //...
   public ProviderMeta()
   {
     Roles = new int[]{0};
   }
}

将其从投影中删除

 select new ProviderMeta
        {
            LoginId = user.LoginId,
            AgencyId = user.AgencyId,
            Application = user.Application,
            UserId = user.UserId,
            Name = agencySnapshot.Name,
            //Roles = new int[0], remove this line
            Cluster = app.ClusterId ?? 0,
            Created = app.Created,
            TitleType = user.TitleType,
            Feature = (foundFeature == null ? 0 : foundFeature.Feature)
        }).ToList();