Fluent NHibernate mapping

后端 未结 5 1764
天涯浪人
天涯浪人 2021-02-06 02:21

I\'m new to NHibernate and Fluent NHibernate.

Assuming I have a situation like the following

Table Activities (uniquidentier ID, varchar ActivityName)
Ta         


        
5条回答
  •  孤独总比滥情好
    2021-02-06 02:27

    Based on your hint, i've come to:

    WithTable("Activities"); 
    Id(x => x.Id).ColumnName("ID").GeneratedBy.Guid(); 
    Map(x => x.ActivityName).Not.Nullable().WithLengthOf(50); 
    HasMany(x => x.ActivityParameters) 
            .Cascade.Delete() 
            .KeyColumnNames.Add("ActivityID") 
            .AsMap("ParameterName") 
            .AsMap("ParameterValue") 
            .WithTableName("ActivityParameters");
    

    but i get an error, Association references unmapped class: System.Object. :(

    Later edit: I got the latest version of Fluent, and now the code looks like this:

    Table("Activities");
            Id(x => x.Id).Column("ID").GeneratedBy.Guid();
            Map(x => x.ActivityName).Not.Nullable().Length(50);
            HasMany(x => x.ActivityParameters)
                .KeyColumn("ActivityID")
                .ForeignKeyCascadeOnDelete()
                .Table("ActivityParameters");
    

提交回复
热议问题