---
lang: en
title: 'API docs: repository.defaultcrudrepository.entitytodata'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.defaultcrudrepository.entitytodata.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [DefaultCrudRepository](./repository.defaultcrudrepository.md) &gt; [entityToData](./repository.defaultcrudrepository.entitytodata.md)

## DefaultCrudRepository.entityToData() method

This function works as a persist hook. It converts an entity from the CRUD operations' caller to a persistable data that can will be stored in the back-end database.

User can extend `DefaultCrudRepository` then override this function to execute custom persist hook.

<b>Signature:</b>

```typescript
protected entityToData<R extends T>(entity: R | DataObject<R>, options?: {}): Promise<legacy.ModelData<legacy.PersistedModel>>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  entity | R \| [DataObject](./repository.dataobject.md)<!-- -->&lt;R&gt; | The entity passed from CRUD operations' caller. |
|  options | {} | <i>(Optional)</i> |

<b>Returns:</b>

Promise&lt;legacy.ModelData&lt;legacy.PersistedModel&gt;&gt;


