Search code examples
c#arraysentity-frameworklinqlinq-to-entities

The LINQ expression node type 'NewArrayBounds' is not supported in 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();

Here, Roles is an integer array but it is not letting me assign an empty array with zero. Help would be appreciated.


Solution

  • Initialize the array in an empty constructor of your class:

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

    And remove it from the projection

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