---
lang: en
title: 'API docs: repository.defaultcrudrepository.entitytodata'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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 | <code>R &#124; DataObject&lt;R&gt;</code> |  |
|  options | <code>{}</code> |  |

<b>Returns:</b>

`Promise<legacy.ModelData<legacy.PersistedModel>>`


