public void Generate(IDbConnection connection, SqlDb <TKey> db, Action <TRecord> setProperties = null) { _connection = connection; _db = db; foreach (var record in Records) { // apply any tenant-specific properties, such as an OrgId setProperties?.Invoke(record); var existingRecord = connection.QuerySingleOrDefault <TRecord>($"SELECT * FROM {ExistsCriteria}", record); // this will cause the existing seed record to be updated instead of inserted if (existingRecord != null) { record.Id = existingRecord.Id; } db.Save(connection, record); } }
/// <summary> /// Override this and parse the originalMessage to determine a more friendly error message /// </summary> /// <param name="originalMessage">Message from the original exception</param> /// <returns></returns> public virtual string GetErrorMessage(SqlDb <TKey> db, string originalMessage) { return(originalMessage); }
/// <summary> /// Override this to perform an action after a record is successfully deleted /// </summary> public virtual void AfterDelete(IDbConnection connection, SqlDb <TKey> db) { // do nothing by default }
public virtual bool AllowDelete(IDbConnection connection, SqlDb <TKey> db, out string message) { message = null; return(true); }
/// <summary> /// Use this to set any properties that should update every time a record is saved, for example user and datestamps /// </summary> public virtual void BeforeSave(IDbConnection connection, SqlDb <TKey> db, SaveAction action) { // do nothing by default }
/// <summary> /// Override this to set any properties of a record, and execute foreign key lookups before it's viewed via the Find or FindWhere methods /// </summary> public virtual void BeforeView(IDbConnection connection, SqlDb <TKey> db) { // do nothing by default }