Skip to content

Commit 83cbaaf

Browse files
committed
feat: Add ToModel() extension method
1 parent c4354c4 commit 83cbaaf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using VirtoCommerce.Platform.Core.Common;
2+
using VirtoCommerce.Platform.Core.Domain;
3+
4+
namespace VirtoCommerce.Platform.Core.Extensions;
5+
6+
public static class IDataEntityExtensions
7+
{
8+
public static TModel ToModel<TEntity, TModel>(this IDataEntity<TEntity, TModel> entity)
9+
{
10+
return entity.ToModel(AbstractTypeFactory<TModel>.TryCreateInstance());
11+
}
12+
}

src/VirtoCommerce.Platform.Data/GenericCrud/CrudService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using VirtoCommerce.Platform.Core.Common;
1010
using VirtoCommerce.Platform.Core.Domain;
1111
using VirtoCommerce.Platform.Core.Events;
12+
using VirtoCommerce.Platform.Core.Extensions;
1213
using VirtoCommerce.Platform.Core.GenericCrud;
1314
using VirtoCommerce.Platform.Data.Infrastructure;
1415

@@ -331,7 +332,7 @@ protected virtual void ClearSearchCache(IList<TModel> models)
331332

332333
protected virtual TModel ToModel(TEntity entity)
333334
{
334-
return entity.ToModel(AbstractTypeFactory<TModel>.TryCreateInstance());
335+
return entity.ToModel();
335336
}
336337

337338
protected virtual TEntity FromModel(TModel model, PrimaryKeyResolvingMap keyMap)

0 commit comments

Comments
 (0)