Posts

Showing posts with the label entity framework

Entity Framework Search

Image
Search is a common requirement in most business applications. In this post we will examine searching in Entity Framework and create a query object that encapsulates the common functionality of filtering, sorting, and paging.

Entity Framework Code First Demo

Image
I just created my first video on YouTube! In the video I demonstrated creating a database using the Entity Framework Code First workflow. Watch it below!

Auditing Changes with Entity Framework

Image
Today we will see how we can keep an audit record of entity changes using Entity Framework. This is a very useful feature that can also be a business requirement when dealing with important or sensitive information.

How to View SQL Queries Generated by Entity Framework

Image
Entity Framework works by translating C# code into SQL statements, executing those statements on a target database, and taking care of mapping any return values back to C# objects. But have you ever wondered what the generated SQL statements actually look like? In this post we will be using a free and simple tool that lets us view the SQL executed on the database.

Why Use ViewModels?

Image
Let's talk about a simple but important topic: why use viewmodels in our web applications. Specifically, the kind of viewmodels that we will be talking about are the ones that are used as parameters or return values in controllers.

Why I Don't Use the Repository Pattern When Working with Entity Framework

Image
Today I'm going to talk about a slightly controversial topic about using the repository pattern in combination with an ORM such as Entity Framework.

Creating a Generic Lookup Service

Image
In a previous post I talked about how we can manage lookup tables with Entity Framework Code First . In that post I suggested using the primary key directly to check for a specific lookup, rather than introducing an arbitrary column that will serve as an identifier. In this post I will talk about how we can make a generic lookup service to simplify how we show lookup values in, say, dropdown lists.

Managing Lookup Tables with Entity Framework Code First

Image
Oftentimes in our applications we will have such things as a "lookup table". I am defining a lookup table as a list of relatively fixed or static choices such as status codes, states or provinces, and so on. In this post I will share how I manage lookup tables using Entity Framework.

Loading Related Data in Entity Framework

Image
There are three behaviors that entity framework can use when loading related data. These are lazy loading , eager loading , and explicit loading . The main difference between the three are in when the related data gets loaded and whether it is done behind-the-scenes or explicitly. In this post we will learn about these behaviors and evaluate when one should be used over the other.

Using AutoMapper in Entity Framework Projections

Image
AutoMapper is a wonderful tool that lets us convert one class to another using fluently-defined configurations. It is useful when there is a need for multiple mappings, such mappings from persistence model classes to domain model classes or mapping from domain model classes to viewmodels. In this post we are going to look at how to use AutoMapper with Entity Framework for projections.

Separating Business Rules from Data Access

Image
Business rules can be mixed into data access code. This scenario is a violation of the Single Responsibility Principle, because the data access class would have to change if the business rules change. In this post I will show you how to separate the business rules from the data access code.

Using NLog to Log to a Database with Entity Framework Code First

Image
NLog is a logging framework that is used to add logging capabilities to a .NET application. Today I am going to show how to use NLog to generate logs on a database created by Entity Framework Code First.

Entity Framework Code First Migrations

Image
So you've created your entities and had Entity Framework create your database for you. Now, you want to change your entities and of course also change the database schema. How do you go about doing that?

Multiple Many-to-Many Associations - Entity Framework Code First

Image
Entity Framework Code First lets you build domain classes first without an existing database. As soon as a database is needed, Entity Framework will create the database for you based on the shape of your classes. Entity Framework is smart enough to figure out things such as column names, column types, one-to-many associations, many-to-many associations, and more, according to your intentions. But sometimes, we have to explicitly tell the framework what our intentions are. In this post, we will talk about multiple many-to-many relationships.

Validation in Entity Framework Code First

Image
Entity framework code first has support for validation for frequent validation scenarios. In this post, we will look at a couple of ways on how this can be achieved. If you are new to Entity framework code first, you might want to check out my post on entity framework quick start. .

Entity Framework Code First Quick Start

Image
Hi, in this post I will show you how to get started with using Entity Framework.