henkmollema / Dapper-FluentMap

Provides a simple API to fluently map POCO properties to database columns when using Dapper.
MIT License
429 stars 88 forks source link

Error mapping some value object #46

Closed EduardoPires closed 7 years ago

EduardoPires commented 7 years ago

The entire explanation can be found here: http://stackoverflow.com/questions/40881195/mapping-value-objects-with-dapper

I'm trying to map a value object to my domain model. This nested VO isn't a table is just a VO in my rich domain. Simplified scenario when I get the error at application startup:


    public class Cliente
    {
        public Guid Id { get; set; }
        public CPF CPF { get; set; }
    }

    public class CPF
    {
        public string Numero { get; set; }
    }

    public class DapperMappings
    {
        public static void RegisterDapperMappings()
        {
            FluentMapper.Initialize(config =>
            {
                config.AddMap(new ClienteMap());
            });
        }
    }

    public class ClienteMap : EntityMap<Cliente>
    {
        public ClienteMap()
        {
            Map(c => c.CPF.Numero).ToColumn("CPF");
        }
    }

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            DapperMappings.RegisterDapperMappings();
        }
    }

I always receive the same error at application initialization:

Index was outside the bounds of the array.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Using ASP.NET MVC 5, more details about the Stack Trace can be found at StackOverflow link

g-adolph commented 7 years ago

Hey guys actually i use this solution to fix this problem. I think this isn't a solution but maybe a good point to start to fix the problem. I think fluent mapper must have a more sophisticated reflection algorithms do to this.

https://gist.github.com/g-adolph/f0eb5b977006b96e12dff27c4e61212f

EduardoPires commented 7 years ago

@g-adolph Your gist isn't available :(

henkmollema commented 7 years ago

Try copying the link: https://gist.github.com/g-adolph/f0eb5b977006b96e12dff27c4e61212f

g-adolph commented 7 years ago

@henkmollema, if I do a pull request fixing this issue will be accept? I fixed this issue and created a few tests.

henkmollema commented 7 years ago

@g-adolph I guess I'll take this PR in. If you would like to make one, please do.

jbowen014 commented 7 years ago

I'm having the same issue. Is there an ETA on a release for this fix?

Thank you.

nicolastakashi commented 7 years ago

Some news about it?

nicolastakashi commented 7 years ago

Gentlemen!

Based on the discussion we had here in this thread, I took the liberty of looking at the code that @g-adolph put into the gist and implemented it.

I wrote some tests and it seems that everything really works as it should, I did this because talking to several friends of the software community including @EduardoPires we think that this bug is of great importance for the mapping of value objects with domain entities.

I'm waiting for new...