I don’t see Visual Tooling in EF Core. What are my options?

Folks, some of the cool features/workflows that you are used to using in EF 6.x and with some of the prior versions such as Entity First, Database First that provide visual tooling are a thing of the past in EF Core.

Don’t despair; there’s hope. There are some third-part vendors that make tools which can be easily incorporated in your EF Core projects.

Some of the names of these companies are the following:
LLBLGen Pro: It is an entity modeling solution with support for Entity Framework and Entity Framework Core. It lets you easily define your entity model and map it to your database, using database first or model first, so you can get started writing queries right away. Apart from being one of the leading entity modeling solutions for .NET, it can be used with Entity Framework, NHibernate, Linq to SQL and our own ORM, the LLBLGen Pro Runtime Framework (included). It lets you easily define your entity model and map it to your database so you can get started writing queries right away.


Telerik Data Access: If you’ve been a .NET developer, the odds are you’ve probably used at least one of the Telerik products, may it for the good ‘ol battle ship grey forms,  ASP.NET Web Forms, ASP.NET MVC, Mobile, Just Code, Fiddler etc.


Telerik’s Data Access tools solve development problems with the most powerful data access framework. Some of the key features of the Data Access tool from Telerik bring you the following:

  • Mapping and Model Creation including the mapping of Stored Procedures & Functions
  • Change Tracking and CRUD Operations
  • Powerful Runtime Capabilities
  • Performance Optimization
  • Support for Multiple Databases
  • Unique Fluent API Capabilities
  • Data Access Profiler
  • Testability

More information can be obtained here.

DevArt: DevArt is another one of the ORM solution providers. It offers wide set of the .NET database connectivity tools with ORM support. It includes the following ORM tools and solutions:

  • Entity Developer
  • dotConnect
  • LINQ
  • LINQ Connect

DevArtMore information can be obtained here.

Posted in ORM | Comments Off on I don’t see Visual Tooling in EF Core. What are my options?

What does Connection Resiliency offer when using EF Core!

Connection Resiliency comes handy when you have a failed database operation. This operation could be the result of moving a database from one server to another for the purposes of load balancing, thus causing the database to become unavailable for a short period of time even if its for a few seconds.

Another scenario could be that you have deployed a database as a container and for some reason the container is not ready for other container(s) or micro-services etc.

In essence, Connection resiliency retries failed attempts in the event of database connection failure and is specific to relational databases. This feature was recently introduced as part of EF Core’s 1.1 release.

It’s implementation is fairly straight-forward. You need to define the execution strategy  by overriding the OnConfiguring() method in your dbContext or in Startup.cs if using an ASP.NET Core application.

Note the number 5 that I am passing to the EnableRetryOnFailure(5) which denotes of retries if the database commands were to fail. This method has two overloads which in addition to the number of retries, you can also pass in the delay between retries in milliseconds.

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            optionsBuilder.UseSqlServer(@"server=obi-oberoi; database=Demo.Department; Trusted_Connection=True;",
                options => options.EnableRetryOnFailure(5));

Posted in ORM | Comments Off on What does Connection Resiliency offer when using EF Core!

What does EF Core give me out of the box?

As you might know, EF Core is brand new and it has long ways to go before reaching parity with EF 6.x, although some of the features that were murky in EF 6.x will probably never be added to EF Core.

That being said, it has some very good features that not only make the transition from EF 6.x to EF Core smoother, it’s also a lot of fun learning some of goodness of this otherwise new shiny tool.

Make no bones about it. EF Core is production ready and there are a lot features that you can already take advantage of. For example:

  • It’s constantly evolving and Microsoft is betting on it for its success going forward
  • It has the familiar APIs that we are used to like DbContext, DBSet etc.
  • It has full .NET Support in addition to being cross platform (can run on iOS, Linux, Android)
  • It is highly composable and hence lightweight
  • It is built from Ground Up and has APIs that highly performant
  • It supports Relational Databases and will have support for NoSQL databases in the future
  • The entire EF Core stack is open sourced on Github
Posted in ORM | Comments Off on What does EF Core give me out of the box?

Implementing Cascade Delete behavior in EF Core

The definition of Cascade Delete is if a record in the parent table is deleted, the corresponding records in the child table will automatically be deleted.

Now that we know what Cascade Delete is all about, let’s implement this behavior in EF Core where we will use Department and Employee tables. A Department can have one or more Employees. In other words, it’s a One to Many relationship. The idea is when we delete a record in the Department table, any references it has to the deptId key in the Employees table will also be deleted.

In the code that follows, the code loads records from the Department table and its corresponding Employees from the database. Notice the include method that is being used here. When SaveChanges is called, the cascade delete rules will be applied to the entities that are being tracked by the context.

Before Deletion:


private static void CascadeDelete()
            using (var db = new DepartmentContext())
                var depts = db.Departments.Include(e => e.Employees).First();

After Deletion:

CascadeDeleteAfterAs you can see DepID 8 which happened to be the first record in the Department table had two related Employees, namely, Rebecca D’Souza and Chris Wood. When the Department record with an Id of 8 was removed, it also deleted its corresponding Employees.

Since all Employees were tracked by the dbContext, the cascade behavior was applied before saving entries to the database. As a result, Entity Framework issued a DELETE statement for each of the matching entities.

Posted in ORM | Comments Off on Implementing Cascade Delete behavior in EF Core

Can I use Projections in EF Core…Absolutely!!

Before we drill into Projections, let’s find out what Projections really are:

Projection(s) is a powerful feature of LINQ that enables you to perform query operations on a data source, collection etc. It shapes the results of the data being queried into a different structure/format that the original data source is in.

It is a process to express queries in order to return a desired set of data other than the entire entity. Projection queries improve the efficiency of your application by only retrieving specific fields from your database.

A projection query lets you select only the data that is required from your model. It is done, by loading the data into a custom or anonymous type. This significantly improves the performance of your application, especially when you filter out the fields that contain huge amounts of data.

When you use the Select method, you can retrieve scalar properties and also navigation properties to retrieve data in the same query. Please see the code snippet below:

   private static void Projections()
            using (var db = new demo_departmentContext())
                var dept = db.Departments.Select(d => new { d.DepId, d.DepName, d.Location })
                    .Where(d => d.DepName.Contains("IT"))
                foreach (var item in dept)
                    Console.WriteLine("{0} - {1} - {2}", item.DepId, item.DepName, item.Location);

And following is the output:

EFCoreProjectionsOutputAs  you saw above using projections allow us to retrieve a subset of the properties from an object as opposed to the entire object. This causes a smaller amount of data to be returned in the query.

Posted in ORM | Comments Off on Can I use Projections in EF Core…Absolutely!!