简体   繁体   中英

nhibernate mapping from fluent to mapping by code

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});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM