Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping a Component inside a Component Collection

I'm trying to map a value object collection where these contain other value objects but am getting the below exception.

nHibernate Exception:

 ----> NHibernate.PropertyNotFoundException : Could not find a getter for property '_timeAtAddress' in class 'CustomerAddress'

Domain:

public class CustomerAddress
{
    private TimePeriod _timeAtAddress;

    protected CustomerAddress() { }

    public CustomerAddress(TimePeriod timeAtAddress)
    {
        _timeAtAddress = timeAtAddress;
    }

    public TimePeriod TimeAtAddress { get { return _timeAtAddress; } }
}

public class TimePeriod
{
    private readonly int _months;
    private readonly int _years;

    protected TimePeriod() { }

    public TimePeriod(int months, int years)
    {
        _months = months;
        _years = years;
    }

    public int Months { get { return _months; } }
    public int Years { get { return _years; } }
}

nHibernate Mapping:

contact.HasMany<CustomerAddress>(Reveal.Member<Contact>("_customerAddresses"))
    .Schema(...)
    .Table(...)
    .KeyColumn(...)
    .AsBag()
    .Not.LazyLoad()
    .Component(address =>
    {
        .
        .
        .

        address.Component(Reveal.Member<CustomerAddress, TimePeriod>("_timeAtAddress"), timeAtAddress =>
        {
            timeAtAddress.Map(Reveal.Member<TimePeriod>("_years")).Column("TIME_YEARS");
            timeAtAddress.Map(Reveal.Member<TimePeriod>("_months")).Column("TIME_MONTHS");
        });
    });

Had a quick look at Access but can't seem to figure out where to set that up for components. Can you help?

like image 445
J Fernandes Avatar asked Apr 30 '15 13:04

J Fernandes


People also ask

How do you map components in React?

With the map function, we map every element of the array to the custom components in a single line of code. That means there is no need to call components and their props as array elements again and again. Syntax: var array = [1,2,3,4,5] var PlusOne= array.

Can we use map inside map?

To use a map() inside a map() function in React: Call map() on the outer array, passing it a function. On each iteration, call the map() method on the other array.

What is map () in React JS?

In React, the map method is used to traverse and display a list of similar objects of a component. A map is not a feature of React. Instead, it is the standard JavaScript function that could be called on an array. The map() method creates a new array by calling a provided function on every element in the calling array.

How do I map an array in React?

The answer is, you use Array. map() in your component and return JSX elements inside the Array. map() callback function to render the UI.


2 Answers

Rather than configuring FluentNHibernate to set the private field, shouldn't you be telling it to use the constructor argument?

My gut feeling is that the mistake is here:

address.Component(Reveal.Member<CustomerAddress, TimePeriod>("_timeAtAddress")

Where you're telling it to use the field _timeAtAddress.

like image 95
Richiban Avatar answered Oct 11 '22 22:10

Richiban


The only way I managed to move forward (using the private field) was to set a global Access.Field convention.

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Customer>() .Conventions.Add(DefaultAccess.Field()))

like image 20
J Fernandes Avatar answered Oct 11 '22 22:10

J Fernandes