zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.Infrastructure/EntityFrameworks/IncludeRelatedPropertiesOptions.cs
2023-12-05 17:22:48 +08:00

24 lines
840 B
C#

using ZeroFramework.DeviceCenter.Domain.Entities;
namespace ZeroFramework.DeviceCenter.Infrastructure.EntityFrameworks
{
public class IncludeRelatedPropertiesOptions
{
private readonly IDictionary<Type, object> _includeOptions = new Dictionary<Type, object>();
public Func<IQueryable<TEntity>, IQueryable<TEntity>> Get<TEntity>() where TEntity : BaseEntity
{
if (_includeOptions.TryGetValue(typeof(TEntity), out var value))
{
return (Func<IQueryable<TEntity>, IQueryable<TEntity>>)value;
}
return query => query;
}
public void ConfigIncludes<TEntity>(Func<IQueryable<TEntity>, IQueryable<TEntity>> action) where TEntity : BaseEntity
{
_includeOptions.TryAdd(typeof(TEntity), action);
}
}
}