1

最近我在尝试更新 MS SQL 数据库中的实体时遇到了这个错误。

我有两个模型:

[AutoMap(typeof(Employees))]
    [Table("Employees")]
    public class Employees : FullAuditedEntity
    {
        public Employees()
        {
            EmployeesAdresses = new HashSet<EmployeesAdresses>();
            WorkTimeEntries = new HashSet<WorkTimeEntries>();
            ContractEntries = new HashSet<ContractEntries>();
        }

        public string Name { get; set; }
        public string Surname { get; set; }
        public string Description { get; set; }
        public bool IsActive { get; set; }

        public ICollection<EmployeesAdresses> EmployeesAdresses { get; set; }
        public ICollection<WorkTimeEntries> WorkTimeEntries { get; set; }
        public ICollection<ContractEntries> ContractEntries { get; set; }

        [NotMapped]
        public List<GroupRelations> GroupRelations { get; set; }

    }

[AutoMap(typeof(EmployeesAdresses))]
    [Table("EmployeesAdresses")]
    public class EmployeesAdresses : FullAuditedEntity
    {
        public string Street { get; set; }
        public string HouseNumber { get; set; }
        public string ApartmentNumber { get; set; }
        public string PostalCode { get; set; }
        public string City { get; set; }
        public string Phone { get; set; }
        public string Email { get; set; }
        public bool IsDefault { get; set; }
        public bool IsActive { get; set; }


        [ForeignKey("Employees")]
        public int EmployeeId { get; set; }
        public virtual Employees Employee { get; set; }

    }

我正在尝试使用简单的 appservice 更新员工地址:

public async Task UpdateEmployee (Employees employeeInput)
        {
            try
            {

                var _employee = await _employeesRepository.GetAllIncluding(x => x.EmployeesAdresses).Where(x => x.Id == employeeInput.Id).SingleOrDefaultAsync();
                if (_employee == null)
                    throw new Exception($"Brak pracownika o ID: {employeeInput.Id}");

                _employee.EmployeesAdresses.Clear();
                _employee.WorkTimeEntries.Clear();

                ObjectMapper.Map(employeeInput, _employee);

                await _employeesRepository.UpdateAsync(_employee);
            }

            catch (Exception ex)
            {
                throw new UserFriendlyException(@"Wystąpił błąd podczas aktualizacji pracownika.", ex.Message, ex.InnerException);
            }
        }

我收到 StackOverFlowException ,我真的不知道是什么问题。诊断工具事件选项卡中堆栈跟踪的最后一个错误是 StringCompare 错误。

你经历过这样的行为吗?任何想法可能是什么问题?

4

0 回答 0