# Dapper 통합

Dapper Integration

#### 설명

[Dapper](https://github.com/StackExchange/Dapper)는 .NET 용 개체 관계형 매퍼 (ORM)입니다. Axs.Dapper는 Dapper를 Axs에 통합합니다.

#### 설치

시작하기 전에 [Axs.Dapper](https://www.nuget.org/packages/Axs.Dapper)와 EF Core, EF 6.x NuGet 패키지를 사용하려는 프로젝트에 설치해야 합니다.

**모듈 등록**

먼저 등록하는 모듈의 **AxsDapperModule**에 대한 **DependsOn** 속성을 추가해야 합니다 :

```csharp
[DependsOn(
        typeof(StarterPackEntityFrameworkCoreModule),
        typeof(AxsDapperModule)
)]
public class MyProjectNameDbEntityFrameworkCoreModule : AxsModule
{
    public override void Initialize()
    {
        IocManager.RegisterAssembly(typeof(SampleApplicationModule).GetAssembly());
    }
}
```

**Note** AxsDapperModule 종속성은 EF Core 종속성보다 나중에 추가해야합니다.

**엔티티에서 테이블로 매핑**

매핑을 구성 할 수 있습니다. 예를 들어, **User** 클래스는 다음 예제에서 **Users** 테이블에 매핑됩니다 :

```csharp
public class UserMapper : ClassMapper<User>
{
    public UserMapper()
    {
        Table("Users");
        Map(x => x.Roles).Ignore();
        AutoMap();
    }
}
```

매퍼 클래스가 포함 된 어셈블리를 설정해야 합니다. 예 :

```csharp
[DependsOn(
        typeof(StarterPackEntityFrameworkCoreModule),
        typeof(AxsDapperModule)
)]
public class MyProjectNameDbEntityFrameworkCoreModule : AxsModule
{
    public override void Initialize()
    {
        IocManager.RegisterAssembly(typeof(SampleApplicationModule).GetAssembly());
        DapperExtensions.SetMappingAssemblies(new List<Assembly> { typeof(MyProjectNameDbEntityFrameworkCoreModule).GetAssembly() });
    }
}
```

#### 코드에 사용하기

**AxsDapperModule**을 등록한 후 Generic IDapperRepository 인터페이스 (표준 IRepository 대신)를 사용하여 dapper 저장소를 주입 할 수 있습니다.

```csharp
public class SomeAppController : ITransient
{
    private readonly IDapperRepository<User> _userDapperRepository;
    private readonly IRepository<User> _userRepository;

    public SomeAppController(
        IRepository<User> userRepository,
        IDapperRepository<User> userDapperRepository)
    {
        _userRepository = userRepository;
        _userDapperRepository = userDapperRepository;
    }

    public void DoSomePeople()
    {
        // Dapper Context를 통해 일반적인 쿼리를 실행하여 결과값을 받아 올 수 있습니다.
        var people = _userDapperRepository.Query("select * from Users");
    }
}
```

EF와 Dapper 저장소를 동시에 동일한 트랜잭션에서 사용할 수 있습니다!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.axuslab.com/4.-object-relational-mapping/dapper_integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
