2

One Country has many States. One State belongs to one Country. Mapping Country property in StateMap using fluent mapping was

public StateMap()
{
    ...
    References(m => m.Country).Not.Nullable();
}

what is nhibernate mapping by code alternative

should I simply map Country as property

Property(m => m.Country});

1 Answer 1

4

The alternative to References is Mapping-by-Code - ManyToOne

ManyToOne(x => x.Country, m =>
{
    m.Column("column_country");
    // or...
    m.Column(c =>
    {
        c.Name("column_country");
        // other standard column options
    });
...

The HasMany is Mapping-by-Code - Set and Bag

Set(x => x.States, c =>
{ 
    c.Lazy(CollectionLazy.Lazy); // or CollectionLazy.NoLazy, CollectionLazy.Extra

    c.Table("tableName");
    c.Schema("schemaName");
    c.BatchSize(100);
    ...

The links provided above are the best place where to start observing the mapping by code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.