ThommyB
ThommyB

Reputation: 1556

Fluently map a collection of components

I have an object which contains a list of value objects but can't find a solution how to fluently map this. I have a value object mapped as ComponentMap (no inline mapping) like such:

public class ServiceSpecificationMapping : ComponentMap<ServiceSpecification>
{
    public ServiceSpecificationMapping()
    {
        Map(x => x.PurposeOfService).Not.Nullable();
        Map(x => x.Description).Nullable();
        Map(x => x.Price).Not.Nullable();
    }

The containing class has a definition like this:

public class ServiceContract : EntityBase
{
    ....
    public virtual List<ServiceSpecification> ServiceSpecifications { get; set; }
    ...

}

I have difficulties to code the correct mapping. I am looking for something like:

HasMany<ServiceSpecification>(x => x.ServiceSpecifications)
            .Table("tblServiceSpecification")
            .Component(<WHAT IS THE CORRECT LAMBDA HERE??>);

I need to reference the ServiceSpecification instance but I cannot find the correct syntax for that. Any help would be greatly appreciated.

Upvotes: 2

Views: 56

Answers (1)

Phil Degenhardt
Phil Degenhardt

Reputation: 7264

HasMany<ServiceSpecification>(x => x.ServiceSpecifications)
            .Table("tblServiceSpecification")
            .Component(m => {
                m.Map(x => x.PurposeOfService).Not.Nullable();
                m.Map(x => x.Description).Nullable();
                m.Map(x => x.Price).Not.Nullable();
            });

Upvotes: 1

Related Questions