Mapowanie AutoMapper i wyjątek SqlException

0

Witam ponownie.

Mam problem z mapowaniem elementów z bazy danych. Przy wykonaniu poniższego kodu wyrzuca mi wyjątek w linii z komendą return.

 public List<WarehouseContainerDTO> GetWarehouseContainers()
        {
            var containers = db.WarehouseContainers.Where(c => c.CanStoreItems).OrderBy(c => c.WarehouseContainerType.Name)
                .ThenBy(c => c.Symbol).ToList();
            return Mapper.Map<List<WarehouseContainer>, List<WarehouseContainerDTO>>(containers);
        }

AutoMapper.AutoMapperMappingException
HResult=0x80131500
Message=Error mapping types.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
AutoMapperMappingException: Error mapping types.

Inner Exception 2:
AutoMapperMappingException: Error mapping types.

Inner Exception 3:
EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.

Inner Exception 4:
SqlException: Invalid column name 'RepairAction_Id'.
Invalid column name 'WarehouseItem_Id'.

Najbardziej mnie zastanawia wyjątek 4. Faktycznie nie mam takich kolumn. Mam podobne, ale przed Id nie ma podkreślenia. Jeśli chodzi o strukturę klasy WarehouseContainerDto:

public class WarehouseContainerDTO
    {
        public int Id { get; set; }
        public string Symbol { get; set; }
        public bool CanStoreItems { get; set; }

        public WarehouseContainerTypeDTO WarehouseContainerType { get; set; }
        public WarehouseContainerDTO Parent { get; set; }
        public List<WarehouseItemDTO> WarehouseItems { get; set; }
    }

WarehouseItemDTO;

public class WarehouseItemDTO
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Symbol { get; set; }
        public string ManufacturerSymbol { get; set; }
        public int Quantity { get; set; }
        public string SerialNumber { get; set; }
        public string Description { get; set; }

        public WarehouseItemTypeDTO WarehouseItemType { get; set; }
        public WarehouseContainerDTO WarehouseContainer { get; set; }
        public List<RepairActionDTO> RepairActions { get; set; }
    }

I teraz tak, W klasie WarehouseItemDTO mam listę RepairActions. Mam taką samą w klasie bazodanowej WarehouseItem, która służy mi do definiowania many-to-many z tabelą RepairAction.
I taka tabela w bazie jest z kolumnami, o których mówi wyjątek.

I dodam, że ten wyjątek lacie tylko, kiedy w tabeli WarehouseItems mam jakieś dane. Jeśli tabela jest pusta to wyjątku nie ma. Proszę o pomoc, może coś z mapowaniem tego many-to-many...
W razie potrzeby mogę dodać więcej kodu.

0

Zakładam, że masz mapę WarehouseContainer na WarehouseContainerDTO, a czy masz mapę WarehouseItem na WarehouseItemDTO?

0

Oczywiście, że mam.

1 użytkowników online, w tym zalogowanych: 0, gości: 1