I am using AspNet zero framework code first approach, i have two entities , parent questionOption and child entity userAnswer with Fk QuestionOptionId, UserAnswer does not allow duplicate QuestionOptionId even i dont create any index aur unique constrant on questionOptionId (i have mentioned picture). It doesnot give any exception or any error query execute successfully but does not create new duplicate/new record
what i have tried so far
here is my insertLink Query
public async Task RCreateOrEdit(CreateOrEditUserAnswerDto input)
{
var userAnswer = ObjectMapper.Map<UserAnswer>(input);
if (AbpSession.TenantId != null)
{
userAnswer.TenantId = (int)AbpSession.TenantId;
}
await _userAnswerRepository.InsertAsync(userAnswer);
await CurrentUnitOfWork.SaveChangesAsync();
input.Id = userAnswer.Id;
}
this is what SQL SERVER created

ChildModel
public class UserAnswer : FullAuditedEntity<long>, IMustHaveTenant
{
public int TenantId { get; set; }
public virtual long UserId { get; set; }
public virtual long QuestionId { get; set; }
public string UserComment { get; set; }
public virtual long SessionId { get; set; }
[ForeignKey("SessionId")]
public Session SessionFk { get; set; }
public virtual long QuestionOptionId { get; set; }
public QuestionOption QuestionOptionFk { get; set; }
}
Desired Result: I want UserAnswer entity will allow me to add duplicate QuestionOptionFk
public class UserAnswer : FullAuditedEntity<long>, IMustHaveTenant
{
public int TenantId { get; set; }
public virtual long UserId { get; set; }
public virtual long QuestionId { get; set; }
public string UserComment { get; set; }
public virtual long SessionId { get; set; }
[ForeignKey("SessionId")]
public Session SessionFk { get; set; }
public virtual long QuestionOptionId { get; set; }
public ICollection<QuestionOption> QuestionOptionFk { get; set; }
}
Define relation using array of class instead of class according to Conventions of one to many relationship
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With