---
title: "Entity framework - get entity by name."  
description: "Entity framework - get entity by name."  
author: "Revati S Misra"  
published: 2023-09-05  
updated: 2023-09-06  
canonical: https://www.mindstick.com/forum/159846/entity-framework-get-entity-by-name  
category: "asp.net core"  
tags: ["c#", "entity framework"]  
reading_time: 2 minutes  

---

# Entity framework - get entity by name.

[Entity framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) - get entity by name.

## Replies

### Reply by Aryan Kumar

You can also use the [Entity](https://www.mindstick.com/forum/160562/database-connectivity-using-entity-framework-database-first-approach) [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) to retrieve an entity by name using the `Find` method of the DbContext class. The `Find` method takes an entity name of the entity as a parameter and returns an object of that entity type.

The following code gets an entity by name:

C#

```plaintext
var entity = context.Find<Entity>(name);
```

where `Entity` is the name of the entity type and `name` is the name of the entity.

The find method returns null. If the entity does not exist.

Here are some other things to keep in mind when getting entities by name using Entity Framework:

- You can use the `Where` operator to filter the query result.
- You can use the `OrderBy` operator to order the query result.
- You can use the `Take` and `Skip` operators to paginate the query result.

Here is an example of how to get an entity by name in Entity Framework Core:

C#

```plaintext
using System.Linq;

namespace EFCoreDemo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Create a DbContext
            using var context = new MyContext();

            // Get the entity by name
            var entity = context.Find<Customer>(name);

            // Print the entity name
            Console.WriteLine(entity.Name);
        }
    }

    public class MyContext : DbContext
    {
        public DbSet<Customer> Customers { get; set; }
    }

    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}
```

In this example, we first create a DbContext called `MyContext`. Then use the `Find` method to get the entity named `name`. Finally, we print the name of the entity.


---

Original Source: https://www.mindstick.com/forum/159846/entity-framework-get-entity-by-name

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
