Check your CustomerDetail object after inserting, the ID will be populated already
public class CustomerDetail
{
public int Id{ get; set; }
public string Name{ get; set; }
public string Address{ get; set; }
}
var customerDetail = new CustomerDetail { Name = "Bubbles", Address = "1 way, city" }
customerDetailRepository.Add(customerDetail)
Console.WriteLine(customerDetail.Id); // This is the identity value