# 엔티티 - Entities

Entities

#### 설명

엔티티는 DDD (Domain Driven Design)의 핵심 개념 중 하나입니다. 기본적으로 엔티티에는 ID가 있으며 데이터베이스에 저장되고 테이블에 매핑됩니다. (절대적으로 데이터베이스를 지칭하지 않으며, 영속성을 가진 저장소 기능을 담당할 수 있는 NoSQL로도 매핑이 됩니다.)

"DDD 는 해당 도메인과 일치하도록 소프트웨어를 모델링하는 데 중점을 둔 소프트웨어 설계 접근 방식이다. 한 가지 중요한 특징은 소프트웨어 코드의 구조와 언어가 비즈니스 도메인의 용어를 일치시켜 나간다는 점이다. ([Wikipedia](https://ko.wikipedia.org/wiki/%EB%8F%84%EB%A9%94%EC%9D%B8_%EC%A3%BC%EB%8F%84_%EC%84%A4%EA%B3%84))"

#### Entity Class

Axs에서 엔티티는 **Entity** 클래스에서 상속되어 선언합니다.

```csharp
public class Sample : Entity
{
    public virtual string MyName { get; set; }

    public virtual DateTime CreateTime { get; set; }

    public Sample()
    {
        CreateTime = DateTime.Now;
    }
}
```

**Sample** 클래스는 엔티티로 정의됩니다. 두 개의 속성과 Entity 기본 클래스에 정의 된 Id 속성이 있습니다. Id는 엔티티의 기본 키입니다. 모든 엔티티의 **기본 키** 이름은 동일하며 **Id**입니다.

Id (기본 키)의 유형을 변경할 수 있습니다. 기본적으로 **int** (Int32)입니다. 다른 유형을 Id로 정의하려면 아래와 같이 명시 적으로 선언해야합니다 :

```csharp
public class Sample : Entity<long>
{
    public virtual string MyName { get; set; }

    public virtual DateTime CreateTime { get; set; }

    public Sample()
    {
        CreateTime = DateTime.Now;
    }
}
```

#### 암묵적인 인터페이스

Axs에서는 엔티티에서 여러가지 케이스에서 사용가능한 암묵적인 인터페이스를 제공합니다. 이는 이러한 인터페이스를 구현하는 엔티티에 대한 공통 코드를 코딩하는 방법을 제공합니다.

**임시 삭제 - Soft Delete**

임시 삭제는 실제로 데이터베이스에서 삭제하는 대신 엔티티를 삭제됨으로 표시하는 데 사용되는 패턴입니다. 예를 들어, 다른 테이블과 많은 관계가 있으므로 데이터베이스에서 사용자를 삭제하지 않을 수 있습니다. **ISoftDelete** 인터페이스는 다음과 같은 목적으로 사용됩니다 :

```csharp
public interface ISoftDelete
{
    bool IsDeleted { get; set; }
}
```

엔티티가 삭제 될 때 Axs는 이를 감지하고 IsDeleted를 true로 설정 한 다음 데이터베이스에 엔티티를 저장합니다. 또한 자동으로 필터링하여 데이터베이스에서 일시 삭제 된 엔티티를 검색하지 않도록 합니다.

**IDeletionAudited** 인터페이스를 사용하여 일시 삭제를 사용하는 경우 엔터티가 삭제 된 시기와 삭제 한 사람에 대한 정보도 저장할 수 있습니다.

```csharp
public interface IDeletionAudited : ISoftDelete
{
    long? DeleteId { get; set; }

    DateTime? DeleteTime { get; set; }
}
```

엔터티에 대한 모든 감사 인터페이스 (생성, 수정 및 삭제)를 구현하려는 경우 **IFullAudited**가 다른 항목에서 상속되므로 직접 구현할 수 있습니다 :

```csharp
public interface IFullAudited : IAudited, IDeletionAudited
{

}
```

바로 가기로 모든 항목을 구현하는 **FullAuditedEntity** 클래스에서 상속하여 사용 할 수 있습니다.


---

# 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/2.-domain-layer/entities.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.
