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. 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. Published on Jun 21, 2022 Tags: Entity Framework Tutorials For Beginners and Professionals
| linq
Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article
that you just finished reading.
No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner
or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in
and improve your skillset with any of the tutorials below.
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))
});
Related Posts
Tutorials
Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.