Category: Entity Framework

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

    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

    (more…)

  • Detaching specific objects using Entity Framework before SaveChanges

    Sometimes in large processes that span across multiple classes, it’s possible that an entity is added to Entity Framework’s context tracking. I’ve run into this scenario where we accidentally save things that get immediately deleted afterwards.

    Let’s look at a neat solution that will allow you to detach specific objects out of Entity Framework’s context. In theory this can go in several places: In the code you know causes the entities to be added or before the call to SaveChanges. In this example we’ll look at the latter because it is a nice and generic spot.

    (more…)

  • Entity Framework Stored Procedure Returns No Columns

    I was recently adding a new stored procedure to my Entity Framework EDMX (database first) when no columns were being recognized by EF. I was slightly confused by this, luckily I found this simple solution. At the top of your stored procedure definition, add SET FMTONLY OFF. I suggest only adding this setting temporarily; further explanation is below.

    (more…)

  • Using ActionFilterAttribute to validate all form input

    I’m a big fan of using ActionFilterAttribute to apply a global filter on every single ASP.NET MVC request. I am going to create a custom filter that will implement ActionFilterAttribute to validate that the ModelState is valid for all POST or PUT requests.

    (more…)

  • Improving the performance of slow Entity Framework queries

    I’m a big fan of Entity Framework. It makes working with databases very convenient. I’ve discussed previously how I use Entity Framework to implement the repository pattern. Of course with ease of development sometimes sacrifices performance. In today’s article I’m going to explain my favorite approach to improve the performance of Entity Framework queries that are slow.

    (more…)