Skip to content

Incorrect usage of mappings

Dmitry Bezzubenkov edited this page Apr 15, 2018 · 8 revisions

When you try to apply mapping expression to IQueryable interface, you can catch a few different types of exceptions. Please see the list below, it described all internal MappingException messages supported by QueryMapping library.

  • Mapping from {0} to {1} was not found

    Mapping with direction, that you are trying to apply, wasn't found. It can happen because of a few different reasons. First, you may really forgot to register this mapping. Second, your IMappingStorage implementation, that describes current mapping, wasn't found (check that IMappingStorage is located in one of assemblies registered at the start of application. See more details here)

  • More than one mapping from {0} to {1} was found. If you have more than one mapping for the same model you can use Named Mappings (see documentation) or create different models for different mappings

    You probably have more than one mapping with the same direction across all of your IMappingStorage implementations and all of them doesn't have any name associated with them. You can have more than one mapping with the same direction only if you associate some unique name with every of the mappings. Check Named Mappings for more details.

  • A few mappings from {0} to {1} were found, but 'name' argument wasn't passed into method. Can't choose correct one. Please pass 'name' argument explicitly

    This error message means that necessary mapping was found, but we found more than one of mappings with the same direction. To resolve this issue you need to check that all of these mappings have associated with them name (see Named Mappings) and that you passed name argument into AsQuery method.

  • Mapping from type {0} to type {1} was found, but you are using incorrect version of AsQuery method for this type of mapping. You are using AsQuery method that is used {4} arguments and {5} EF context, but founded mapping was registered {2} arguments and {3} EF context

    You will catch this exception if your mapping was registered with arguments or with injected EF Context (or both of them), but you didn't pass arguments or context key (or both of them) into AsQuery method. Please double check that you invoke AsQuery method with the same arguments as you use in your mapping expression.

  • Arguments can't be null for this overload of AsQuery method

    Arguments is required parameter, you can't pass null instead of them. In the case when arguments is null, you probably need to register your mapping without arguments and use another version of AsQuery method.

  • Context Key was null. In Current version Context Key is required parameter.

    If you want to use mapping with injected EF context, you have to pass context key. Context Key is an any identificator that you can use when you resolve EF Context with DI container. With help of context key you can inject different implementations of EF Context in the same application. But even if you have only one EF Context in your project, you have to pass any context key into method.

  • Exception has happened on attempt to apply mapping. See the Inner Exception for more details

    Some general exception has happened when mapping was applied to IQuerybale interface. That means mapping was successfully found and correct version of mapping is being used, but some other error has happened. Please see Inner Exception to find more details.