EntitySet.Where(myPredicate) throws NotSupportedException

前端 未结 3 907
不知归路
不知归路 2021-01-18 15:34

EDIT: Let\'s try this again. This time I\'ve used the AdventureWorks sample database so you can all play along. This will rule out anything crazy I\'ve do

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 16:11

    Try this:

    Expression> activePlanPredicate = plan => plan.CancelDate == null && plan.UpgradeDate == null;
    var result = from subAccount in db.SubAccounts
             select new ServiceTicket
             {
                 MaintenancePlans = subAccount.Maintenances.Where(activePlanPredicate).Select(plan => plan.ToString()).ToArray()
                 // Set other properties...
             };
    

    I don't have VisualStudio in front of me, so that may require some tweaking. The issue you're running into is that you want to access the IQueryable extension of Where, but just having a Func gives you the IEnumerable extension.

提交回复
热议问题