ASP.NET Core 2: LLBL + Entity Framework Core


LLBL is an awesome ORM that’s been around for a long time, is actively worked on, has amazing tech support and produces rock solid code. I don’t own stocks, I just love the tool.

This article assumes you have a little bit of experience with LLBL. We’ll be using a new Database and the Database-first design, but you can change that to what suits you.

I’m skipping certain best practices, like using a repository pattern,  for the sake of simplicity.

Step 1: Create a database with a login and at least 1 table.


Step 2: Create a New LLBL Project for Entity Framework Core v2 and save it in the ASP.NET Core solution folder. Database first

create llbl.png

Step 3: Using the dialog that appears, connect to your database and choose the table(s) you’d like to add

llbl connect.png

Step 4: Add the Tables as Entities

reverse LLBL.png

Step 5: Press the Generate Code button and then the Edit Selected Task Specifics. Change the Destination root folder to .\LLBL

llbl folder.png

Step 6: Press the Perform Tasks button to generate the LLBL projects. Close LLBL.

Step 7: Open Visual Studio 2017 and the ASP.NET Core project. Add the 2 new projects LLBL just created

Step 8: Add a reference to the LLBL projects to your ASP.NET Core main project

Step 9: Add these NuGet Packages to the LLBL Persistence project:

  1. Microsoft.EntityFrameworkCore
  2. Microsoft.EntityFrameworkCore.Relational

Step 10: To the LLBLPersistence project’s DataContext class add a partial file and add this new constructor so ASP.NET Core can pass options to it.

	public partial class FinanceTooDataContext 
	    public FinanceTooDataContext(DbContextOptions<FinanceTooDataContext> options)

Step 11: Add the LLBL DataContext options to the ConfigureServices of Startup.cs

public void ConfigureServices(IServiceCollection services)
   services.AddDbContext<FinanceTooDataContext>(options => options

Step 12: Add LLBLConnection to appsettings.json

  "ConnectionStrings": {
    "LLBLConnection""data source=.\\sqlexpress;initial catalog=FinanceToo;User ID=MyUserName;Password=password;persist security info=False;packet size=4096"

Step 13: Access the data context in a controller! Done

public class HomeController : Controller
    public HomeController(FinanceTooDataContext context)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s