Let DB set default value?

I have a model that has the following property:

	public int AccountNumber { 
		get => _AccountNumber;
		set {
			CompareChange(_AccountNumber, value);
			_AccountNumber = value;
		}
	}

The table in SQL (SQL Server) has a default set for that column such that it returns the next number from a sequence.

[AccountNumber] INT NOT NULL DEFAULT next value for AccountNumberSequence

How do I enable the following through OrmLite:

  • When saving a new model, the update statement must not send through the AccountNumber field for this specific POCO. This will allow the database to set it’s default value. I tried to make it int? but the field is marked as non-nullable and the update statement will try to set the field to null which throws a SQLException. I cannot make it a private set as this property may actually be set somewhere else.
  • This value must still be retrieved from the database when doing a select.
  • On Save for the first time, how do I get the default value set by the database back? Will I need to make another query?

Any ideas on how to accomplish this?

I am using OrmLite 4.5.12.

You can ignore fields in Updates by using a nullable property and updating with db.UpdateNonDefaults() or specify which fields you want updated using db.UpdateOnly() APIs or annotating the property with the [Compute] attribute.

What does the [Compute] attribute do? I didn’t find any docs on it?

It indicates the field is computed.