Open Closed

Entities design tip #869


0
diego created

Hello, i have few questions about entities design, suppose we have these 2 classes

public class Partner : FullAuditedEntity, IPassivable, IMayHaveTenant
{
	public const int MaxNameLength = 100;

	[Required]
	[StringLength(MaxNameLength)]
	public virtual string Name { get; set; }

	[Required]
	public virtual PartnerType PartnerType { get; set; }		
	
	public virtual int? TenantId { get; set; }
	public virtual bool IsActive { get; set; }	
	
}

public class PartnerType : Entity, IPassivable, IMayHaveTenant
{
        public const int MaxNameLength = 100;

        [Required]
        [StringLength(MaxNameLength)]
        public virtual string Name { get; set; }

        public virtual int? TenantId { get; set; }
        public virtual bool IsActive { get; set; }	
}

1 - It's right use the [Required] attribute on the PartnerType property of the Partner class? 2 - Whenever there is a relation between class, i must use the ForeignKey attributes? 3 - With the [Required] attribute on the PartnerType property of the Partner class i have a issue trying deleting a Partner, below the code

public async Task DeletePartner(IdInput input)
{	
	await _partnersRepository.DeleteAsync(input.Id);
}

The delete (indeed soft delete) fail reporting this validation error: "The PartnerType field is required". Why?

Thanks in advance, Diego


No answer yet!