Showing all posts tagged: 'Entity Framework'

A 9-post collection

Query Profiling on Azure SQL

[Azure SQL](https://azure.microsoft.com/en-us/services/sql-database/?v=16.50" target="_blank) is one of the most valuable Platform as a Service (PaaS) offerings on Azure, second only to Web Apps. It's incredibly cost effective and fully featured. It supports a number of database versions and can be deployed in seconds. The other day I was looking to test something with EF Core and I needed a database to run queries against. I went to the Azure portal, I created a database with prepopulated data using the AdventureWorks (Datawarehouse Workload - DW) and I was ready …[read more]


EF Core migrations with existing database schema and data

I'm currently working on an inherited .NET Core project and I'm loving the experience. I'm still using the project.json project format instead of the newer *.csproj & msbuild one. For now I'll leave it as it is but going forward I'll use the new format for subsequent ASP.NET Core projects. The project also makes use of the newest [EF Core](https://docs.microsoft.com/en-gb/ef/" target="_blank) so it's all running on the edge of the .NET technology. EF Core Code First is great but the tooling is still rough around the edges. Some things …[read more]


Entity Framework Core 1.0 - Table Valued Functions and LINQ Composition

Entity framework Core (EFCore) has been out for a few weeks now after hitting RTM on June 27th 2016. That was also the same day that ASP.NET Core was released. EFCore has brought many changes, to say the least. It was renamed to Core instead the logical continuation from Entity Framework, because it's a total rewrite. Very similar to ASP.NET Core. The rewrite brought many benefits with speed being the biggest one. EF Core is simpler and a lot more powerful, even though it's still early days and some things are not working as expected or are missing. …[read more]


Performance issues with multiple includes and large object graphs - Entity Framework

Entity Framework (EF), Microsoft's ORM answer to nHibernate, is an excellent tool. I've used it many times in many projects. It's easy to get started and set up, it's versatile and has good support. Unfortunately, as with every other tool, there are pitfalls. The larger a project gets, the harder it becomes to use EF straight out-of-the-box. As your objects and relationships grow, your queries need to become more intelligent. More refined. There are many ways to mitigate performance issues, BDD, multiple contexts, query optimization, AutoMapper, etc. I could probably do another post or posts just on this subject! And …[read more]


The specified type member 'Date' is not supported in LINQ to Entities Exception - Entity Framework

EntityFramework is great when it works. You almost don't know it's there, doing its magic in the background while you focus on building your application around your models. However, when it breaks or doesn't work in the way you expect it, you're in for a ride. This morning I spent a bit of time trying to figure out why I was getting the following error on a seemingly straightforward query: The specified type member 'Date' is not supported in LINQ to Entities Exception So, why is this failing? The answer to the question is simple: "LINQ to Entities cannot …[read more]


Logging and tracing with Entity Framework 6

Logging is important, especially when you have to troubleshoot an issue. That's when you realize that without logging you are "driving blind". Today's post is about logging with Entity Framework 6. I agree that there are tools out there that can help you with EF troubleshooting, such as Glimpse (if you are on a web application), SQL Server profiling etc. However, EF6 makes it extremely easy to log and trace executed statements and in this post I will show you how you can leverage this feature to create a robust and efficient logging solution for your application. Simple …[read more]


Generic Repository with Entity Framework

My first NuGet package and OSS project is live :) What an exciting day! Lots of new releases announced in the last couple of days so why not add to the funfair and release my own OSS? This is a piece of code that I had to develop for a client and it took some effort. During the development of this library I tried to make as generic and modular as possible, which made it quite easy when I decided to share it with the community. The project is now live and there is a public repo on GitHub in hope …[read more]


Working with DbGeography, Points and Polygons in .NET

One very handy feature of the System.Data.Spatial namespace is the DbGeography class that allows you to work with either points on a "map" or shapes/polygons. To create a DbGeography point object you need to know the latitude and longitude of that point. There are many services that allow lookup these values for a given place, so we can pass the string "Glasgow" and get back the values 56.033113,-4.789563 as a latitude/longitude pair. How can we convert these values to a DbGeography point? Like this: public static DbGeography ConvertLatLonToDbGeography(double …[read more]