locked
Issue with contains and GetValueOrDefault RRS feed

  • Question

  • User1034446946 posted

    I have this in a link query in my service layer

    public List<ModelA> GetAllAllowed(Guid[] excludedIds)
            {
               
    
                return _someRepository.GetItems(t => t.ModelB.Where(s => excludedIds.Contains(s.Id.GetValueOrDefault())).Count() == 0).ToList();
            }

    which does to the repsoitory which just adds it to a where statement

    the Id it is validation against is a Guid?

    now if I leave off the GetValueOrDefault(), it won't build and

    i get the error:

    'Guid[]' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains<Guid?>(IQueryable<Guid?>, Guid?)' requires a receiver of type 'IQueryable<Guid?>'

    However if i add GetValueOrDefault(), it builds without error but I get this error

    LINQ to Entities does not recognize the method 'System.Guid GetValueOrDefault()' method, and this method cannot be translated into a store expression.

    I am trying to get all of the modelA where there isn't a link with the listed Id's

    Any information would be appriciated.

    Monday, November 14, 2016 11:46 AM

Answers