0
manojreddy created
I have a class which is having another class object as a member, When I call UpdateAsync it gives an error.
My question is why is it giving this error, its an update call not insert call so it should not give this error. ABC is a separate table.
Cannot insert explicit value for identity column in table 'ABC' when IDENTITY_INSERT is set to OFF.
public async Task UpdateTestsAsync(TestDto input)
{
var classobj = GetAll().Where(a => a.Id == input.Id).FirstOrDefault();
ObjectMapper.Map(input, classobj);
await UpdateAsync(classobj);
}
public class TestDto : FullAuditedEntityDto
{
public string TestName { get; set; }
public FetchABC abc { get; set; }
public int AbcId { get; set; }
public int Id { get; set; }
}
public class ABC : FullAuditedEntity
{
public virtual string TestName { get; set; }
public virtual ABC abc { get; set; }
public virtual int AbcId { get; set; }
}
So to make the above code working I'm doing
classobj.abc= null;
before
await UpdateAsync(classobj);
Is it good practice? Do you have any suggestions or better approach?
2 Answer(s)
-
0
I have modified my question. Please remove your comment.
-
0
Hi,
I assume the problem is related to entity FetchABC in your Dto class. You should not include entities in your DTO classes, please replace it with a equivalent dto class.