.net – What Does ‘Insert = true’ mean on an Castle Active Record Association – Education Career Blog

I am working on a project using Castle Active Record. I stumbled across the “Insert = true” attribute argument on the AR association today, but I couldnt workout what it actually does.

BelongsTo("UserId",Insert = true)
public ARUser User {
  get { return mUser; }
  set { mUser = value; }
}

Can someone give me a clue? I couldn’t find the answer in the documentation.

,

Yep, you’ll find the Insert and Update property on a few AR attributes..

I had to do a little testing to make sure I understood the documentation.

Having both Update and Insert set to false indicates that the property will be readonly to your database access (with a public setter this could get confusing.)

Property(Insert=false, Update=false)
public virtual string Name { get; set; }

Having update set to true and insert to false indicates that setting this property and then inserting the element will not set that value in the database.

Property(Insert=false)
public virtual DateTime Created { get; set; }

As for usage scenarios, you’re on your own.

,

From the documentation – Set to false to ignore this association when inserting entities of this ActiveRecord class.

Leave a Comment