-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
Dima Bezzubenkov edited this page Sep 26, 2021
·
16 revisions
There are a few simple steps to start using QueryMappings:
- Describe mappings by implementing IMappingsStorage interface
- Register mappings using MappingsConfiguration class
- Apply mappings using AsQuery extension method
All mappings should be described in Setup method of IMappingsStorage implementation. Just implement Setup method and use MappingsList class to add new mappings. Every mapping is just a simple Expression that describes how we want to map one model to another:
public class AddressMappings : IMappingsStorage
{
public void Setup(IMappingsList mappings)
{
mappings.Add<Address, AddressModel>(x => new AddressModel
{
Id = x.Id,
BuildingNumber = x.BuildingNumber,
City = x.City,
State = x.State,
Country = (Countries)x.Country,
Street = x.Street,
ZipCode = x.ZipCode
});
}
}
Just pass list of assemblies where your IMappingStorage implementations are located into Register method of MappingsConfiguration class:
MappingsConfiguration.Register(typeof(AddressMappings).Assembly);
public MyService(IMappingService qmService)
{
_qmService = qmService;
}
IQueryable<Address> query = ...
List<AddressModel> models = _qmService.AsQuery<Address, AddressModel>(query).ToList();