Migrating from Linq To SQL to Linq To Entities

I am not sure if it is a sound idea to move all the stuff over to Linq to entities from Linq to SQL. However this current portion of the project that I had started few days ago felt like a really good place to test with Linq to entities. So quickly migrated over my code from Linq to SQL to Linq to entities. Surprisingly except for changing few namespaces and datacontext rest of my Linq queries just complied fine against Linq to entities. After compiling the code, I went ahead and tried to run the application and I met my first exception.

The method 'Single' is not supported by LINQ to Entities. Consider using the method the Method first.

I have been using Single operator in Linq to SQL for ages to search for objects based on primary key value. It always worked I am not sure why Linq to entities does not support querying based on single operator. The error is pretty self explanatory and that using the first operator solves the problem. Just a common gotcha to be aware that if you have any existing Linq to SQL queries that you are migrating to Linq to entities, for the most part they will compile fine but sometimes Linq to entities may not have the implementation available by the provider.

No Comments