0

I'm trying to get the objects from a IQueryable that have some properties equal to the objects from another List.

The query is:

var notificationDataWithoutSettingsTypeTwo =
                    (from nd in notificationsData
                     join tnAc in taskAndNotificationAllCustomersModel on new { nd.TaskId, nd.NotificationType } equals new { tnAc.TaskId, tnAc.NotificationType }
                     select nd);

notificationData is the IQueryable and taskAndNotificationAllCustomersModel is the List on object type:

public class TaskAndNotificationAllCustomersModel
{
    public Guid TaskId { get; set; }

    public NotificationTypes NotificationType { get; set; }
}

notificationData is of a type that has multiple properties, including TaskId and NotificationType.

The problem is that I get this exception:

Unable to create a constant value of type 'TaskAndNotificationAllCustomersModel'. Only primitive types or enumeration types are supported in this context.

EDIT:

After I made the List taskAndNotificationAllCustomersModel as a IQueryable, I get this error:

Unable to process the type '.TaskAndNotificationAllCustomersModel[]', because it has no known mapping to the value layer.

EDIT 2:

Tried it like this:

var notificationDataWithoutSettingsTypeTwo = notificationsData.Where(nd => taskAndNotificationAllCustomersModel.Any(tnac => tnac.TaskId == nd.TaskId && tnac.NotificationType == nd.NotificationType));

and I still get exception 1.

geoko93
  • 45
  • 12
  • You are out of luck - EF simply does not support such operation (and in general filtering by more than one property of in memory collection). If you need to keep the result `IQueryable` and the list is not so big, the option is to build dynamically `||` predicate or `Union` query. If the result can be `IEnumerable`, then you can find some mixed techniques on SO. – Ivan Stoev Apr 10 '17 at 08:56
  • You just cannot do that with EF. Even without EF you will have to declare table variable of specific type (assuming you are using sql server) to be able to join with it. – Evk Apr 10 '17 at 09:21
  • 1
    Please refer to this thread [enter link description here](https://stackoverflow.com/questions/31071944/linq-exception-when-join-a-list-on-a-query-result) – Junlong Wang Feb 24 '19 at 20:44

0 Answers0