-1

I have following Address object:

public class AddressObject
{
    public string Postcode { get; set; }
    public string City { get; set; }
    public string Street { get; set; }

    public AddressObject(string PostCodeString, string CityName, string StreetName)
    {
        Postcode = PostCodeString;
        City = CityName;
        Street = StreetName;
    }

    public AddressObject(string PostCodeString, string CityName)
    {
        Postcode = PostCodeString;
        City = CityName;
    }

    public AddressObject() { }
}

And the following fluent mapping I would like to use based on the constructor above:

Map(x => x.AddressObject).Column("PostCode", "Name").Not.LazyLoad();

Is there a way to use object constructors inside of a fluent mapping class?

Snickbrack
  • 1,253
  • 4
  • 21
  • 56

2 Answers2

1

From the documentation:

...NHibernate requires that all public properties of an entity class are declared as virtual. It also requires a parameter-less constructor: if you add a constructor having parameters, make sure to add a parameter-less constructor too. (ref)

David Osborne
  • 6,436
  • 1
  • 21
  • 35
-1

No there is not! Why do you like to act like this?

First of all, you miss the virtual key word on your properties of AddressObject.

Secondly the Map-Method maps values per column, so no entity is mapped but a single value (string, enum, int, etc).

If you want to reference AddressObject out of another model you have to use Reference(x => ....

DotNetDev
  • 205
  • 1
  • 10
  • okay yes. But I have an atomic table layout means that I am referencing all values with IDs like the postalcode and cityname. That means that I am storing the names in a different table. And if I do a a Reference then nHibernate says that it couldn't Reference a unmapped type String. Which is the type of the postalcode or cityname inside my AddressObject... – Snickbrack Mar 20 '19 at 06:57