user6408649
user6408649

Reputation: 1305

Auto Increment (Identity) does not work in Fluent NHibernate

I'm using Fluent Nhibernate. Mapping class looks following:

public class CategoryMap : ClassMap<Category>
{

    public CategoryMap()
    {
        Id(x => x.CategoryId).UniqueKey("CategoryId").GeneratedBy.Increment();
        Map(x => x.CategoryName).Not.Nullable();

        References(x => x.ParentCategory).Column("ParentCategoryId").Nullable();
    }
}

It is creates table like i need but in SSMS i sight that's CategoryId is not identity.

enter image description here

Why auto increment (identity) does not work?

Upvotes: 2

Views: 3630

Answers (1)

Jamie Ide
Jamie Ide

Reputation: 49251

Use Identity instead of Increment, and you don't need to specify UniqueKey because the primary key has to be unique.

Id(x => x.CategoryId).GeneratedBy.Identity();

I'm not sure what the use case is for Increment or where the latest NHibernate documentation lives but you can read about the different types of ID generators in section 5.1.5.1 here: http://nhibernate.info/doc/nhibernate-reference/mapping.html

Upvotes: 5

Related Questions