Vova Bilyachat
Vova Bilyachat

Reputation: 19494

Fluent Nhibernate and DynamicUpdate

I have NH mapping

public class TblContentMap : ClassMap<TblContent> {

        public TblContentMap() {
            Table("tbl_content");
            DynamicUpdate();

            Id(x => x.Id).GeneratedBy.Identity().Column("id");
....
            Map(x => x.ArticleType).Column("article_type").Not.Nullable();

        }
    }

then in my controller its mapped as

public ActionResult Save(TblContent model)

But when i call flush it throw exception. not-null property references a null or transient value SocialDB.NDbModel.TblContent.ArticleType

Question is why? as i understand dynamic update should track which property was changed and update only that values.

PS. I know that it works if firstly get then update model var item = MvcApplication.CurrentSession.GetContentById(model.Id); item.Content = model.Content.StripHtml(false);

Upvotes: 0

Views: 3354

Answers (2)

Vova Bilyachat
Vova Bilyachat

Reputation: 19494

Generally it works as in EF, to use dynamic update need to select item and update fields then push it to database so it will update only modified fields.

Upvotes: 0

Firo
Firo

Reputation: 30813

DynamicUpdate is for update only, not inserting new objects.

NH is already telling you what the problem is

not-null property references a null or transient value SocialDB.NDbModel.TblContent.ArticleType

set the ArticleType property to some value before saving.

Upvotes: 2

Related Questions