Dapper-Extensions icon indicating copy to clipboard operation
Dapper-Extensions copied to clipboard

Async/Await methods do not appear to use DapperExtensions.DapperExtensions.SetMappingAssemblies

Open ghost opened this issue 7 years ago • 5 comments

If I have a custom mapping that is not in the same assembly, I cannot use DapperExtensions.DapperExtensions.SetMappingAssemblies to set the correct assembly to search. It gives me the error "SqlException: Invalid object name 'CMSContent'." The code to reproduce this is:

// Works as expected
static void GetData()
{
    DapperExtensions.DapperExtensions.SetMappingAssemblies(new[] { typeof(CMSContentMapper).Assembly });
    var cn = new SqlConnection("CONNECTION STRING HERE");
    cn.Open();
    var y = cn.GetList<CMSContent>();
    cn.Close();
}

// Throws an exception
static async Task GetDataAsync()
{
    DapperExtensions.DapperExtensions.SetMappingAssemblies(new[] { typeof(CMSContentMapper).Assembly });
    var cn = new SqlConnection("CONNECTION STRING HERE");
    cn.Open();
    var y = await cn.GetListAsync<CMSContent>();
    cn.Close();
}

In another assembly, I have the following map file:

public class CMSContentMapper : ClassMapper<CMSContent>
{
    public CMSContentMapper()
    {
        Table("CMSContents");
        AutoMap();
    }
}

Im on 1.50.2 of Dapper and 1.6.1 of DapperExtensions.

Do I have an error or am I misunderstanding a concept? Thanks!

ghost avatar Jul 31 '17 19:07 ghost

I have the same issue. The async version ignores the custom class mapper, the non async one works fine.

riovescu avatar Aug 13 '17 08:08 riovescu

I've run into the same issue.

Using 1.50.2 of Dapper and 1.6.3.0 of DapperExtensions.

Pastafarian avatar Sep 06 '17 10:09 Pastafarian

use DapperExtensions.DapperAsyncExtensions.SetMappingAssemblies(assemblies);

noobwu avatar Oct 11 '17 03:10 noobwu

For me both DapperExtensions.SetMappingAssemblies and DapperAsyncExtensions.SetMappingAssemblies did not work.

Is there a specific location where we should call DapperAsyncExtensions.SetMappingAssemblies?

adrianriepl avatar Jul 13 '18 06:07 adrianriepl

Any updates on this? I'm running into the issue as well. DapperAsyncExtensions.SetMappingAssemblies is not working for me..

dominicjordan avatar Apr 23 '22 23:04 dominicjordan