Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Error mapping some value object #46

Closed
EduardoPires opened this issue Nov 30, 2016 · 8 comments
Closed

Error mapping some value object #46

EduardoPires opened this issue Nov 30, 2016 · 8 comments
Labels

Comments

@EduardoPires
Copy link

EduardoPires commented Nov 30, 2016

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
Copy link

g-adolph commented Feb 27, 2017

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
Copy link
Author

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

@henkmollema
Copy link
Owner

@g-adolph
Copy link

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

@henkmollema
Copy link
Owner

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

@jbowen014
Copy link

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

Thank you.

@nicolastakashi
Copy link
Contributor

Some news about it?

nicolastakashi pushed a commit to nicolastakashi/Dapper-FluentMap that referenced this issue Aug 8, 2017
Based on the code snippet that @g-adolph put on issue henkmollema#46 discussion thread.

Now we can map properties of value objects.
@nicolastakashi
Copy link
Contributor

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants