Follow @endyourif rss Facebook LinkedIn

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

Published on Jun 21, 2022

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.


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))
});


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.

Tags: Entity Framework | linq

My Books
ASP.NET MVC 5 With Bootstrap and Knockout.js
Knockout.js Building Dynamic Client-Side Applications
20 Recipes for Programming MVC 3
20 Recipes for Programming PhoneGap
Rapid Application Development with CakePHP