The specified type member is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

T

This morning I was writing an Entity Framework query where I was selecting an object from a model called Invoice to a table called NetsuiteErrorLog. This previously used to be an actual relationship in my EDMX; however, I needed to do some refactoring and remove the direct foreign key from Invoice to NetsuiteErrorLog. When I did this I needed to add a new partial property that mimicked this relationship. When I did that and tried to perform my query I received the generic error:
The specified type member ‘NetsuiteErrorLog’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

Thankfully I was able to solve it, let’s look at how I did that with some code examples to help better paint the picture. Please note, my code may look different from yours because there are a lot of built-in methods that I’ve built to help simplify my LINQ querying.

[code]
var results = Get(predicateBuilder, queryOptions).Select(i => new
{
invoice = i,
netsuiteErrorLog = UnitOfWork.Context.NetsuiteErrorLogs.FirstOrDefault(ns =>
ns.EntityTypeId == EntityType.Invoice
&& ns.EntityId == i.Id
&& ns.NetsuiteErrorReasonId == (netsuiteError != 0
? netsuiteError : ns.NetsuiteErrorReasonId))
});
[/code]

Later on when I’m associating the results from this query to the invoices I had added a new partial property to my invoice object:
public NetsuiteErrorLog NetsuiteErrorLog { get; set; }

The mistake I made is that my property name in the Invoice model is the same as the DBSet in my EDMX. So to solve the “The specified type member is not supported in LINQ to Entities” I had to rename the property in my Invoice model to something more unique, e.g.
public NetsuiteErrorLog MostRecentNetsuiteErrorLog { get; set; }

Hopefully this will help you not bang your head as to why you are receiving this generic error.

About the author

By Jamie

My Books