Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'

后端 未结 7 1677
忘了有多久
忘了有多久 2020-12-14 06:16

I have a method:

public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname)
{
    DataTransfer.ChargeInSchoo         


        
7条回答
  •  没有蜡笔的小新
    2020-12-14 07:02

    SonarQube reported Return an empty collection instead of null. and I had a problem with the error with casting as in the title of this question. I was able to get rid of both only using return XYZ.ToList().AsQueryable(); in a method with IQueryable like so:

    public IQueryable MethodName (...) {
      IQueryable XYZ;
      ...
      return XYZ.ToList().AsQueryable();
    }
    

    Hope so it helps for those in a similar scenario(s).

提交回复
热议问题