Ошибка при передаче в репозиторий новой сущности Entity
Всем привет. Столкнулся с ошибкой. проект на C# с EFCore По части EF все прописано.
Для добавления удаления чтения данных реализован интерфейс с репозиторием.
public interface IRepository<T> : IReadonlyRepository<T>
where T : class
{
Task<Result<T>> UpdateAsync(T entity, CancellationToken cancellationToken, bool updateNullValues = false, string? include = null);
}
В целом репозиторий работает. Через него работал с БД в другой части кода.
Но возникла проблема при дальнейшей работе. Я передаю в репозиторий некоторую новую сущность entity (CallerRequestEntity)
private readonly IRepository<CallerRequestEntity> _repository;
public SwitchViewedReportHandler(IRepository<CallerRequestEntity> repository)
{
_repository = repository;
}
public async Task<Result<CallerRequestEntity>> Handle(SwitchViewedReportCommand request, CancellationToken cancellationToken)
{
return await _repository.UpdateAsync(new CallerRequestEntity()
{
...
}, cancellationToken);
}
и при сборке проекта я ловлю исключение :
System.AggregateException: "Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MediatR.IRequestHandler`2[APRF.HelpService.Application.Services.Requests.ReportRequests.Commands.SwitchViewedReportCommand.SwitchViewedReportCommand,APRF.Common.Models.Result`1[APRF.HelpService.Domain.Entities.CallerRequestEntity]] Lifetime: Transient ImplementationType: APRF.HelpService.Application.Services.Requests.ReportRequests.Commands.SwitchViewedReportCommand.SwitchViewedReportHandler': GenericArguments[0], 'APRF.HelpService.Domain.Entities.CallerRequestEntity', on 'APRF.HelpService.Repository.Repository`1[T]' violates the constraint of type 'T'.)"
TypeLoadException: GenericArguments[0], 'APRF.HelpService.Domain.Entities.CallerRequestEntity', on 'APRF.HelpService.Repository.Repository`1[T]' violates the constraint of type parameter 'T'.
С чем связана эта проблема ?
UPD содержимое CallerRequestEntity
[DataContract]
[Table(Constants.Table.CallerRequestEntity)]
public class CallerRequestEntity
{
[Required]
[Column(Constants.Column.CallerRequestEntity.CallerId)]
public Guid CallerId { get; set; }
[Required]
[Column(Constants.Column.CallerRequestEntity.UserCallEventId)]
public int UserCallEventId { get; set; }
[Column(Constants.Column.CallerRequestEntity.ClassificationId)]
public Guid? ClassificationId { get; set; }
[Column(Constants.Column.CallerRequestEntity.CallTransferDataId)]
public Guid? CallTransferDataId { get; set; }
[Required]
[MaxLength(32)]
[Column(Constants.Column.CallerRequestEntity.RequestNumber)]
public string RequestNumber { get; set; } = default!;
[MaxLength(255)]
[Column(Constants.Column.CallerRequestEntity.AgentId)]
public string? AgentId { get; set; }
[MaxLength(255)]
[Column(Constants.Column.CallerRequestEntity.QueueNumber)]
public string? QueueNumber { get; set; }
[MaxLength(20)]
[Column(Constants.Column.CallerRequestEntity.ReceptionNumber)]
public string? ReceptionNumber { get; set; }
[Required]
[MaxLength(20)]
[Column(Constants.Column.CallerRequestEntity.PhoneNumber)]
public string CallerPhoneNumber { get; set; } = default!;
[Required]
[Column(Constants.Column.CallerRequestEntity.OutboundType)]
public CallOutboundType OutboundType { get; set; }
[Column(Constants.Column.CallerRequestEntity.Annotation)]
public string? Annotation { get; set; }
[Required]
[Column(Constants.Column.CallerRequestEntity.IsRead)]
public bool IsRead { get; set; }
[Required]
[Column(Constants.Column.CallerRequestEntity.SpecialTransfer)]
public bool SpecialTransfer { get; set; }