コード例 #1
0
ファイル: SeedData.cs プロジェクト: manhnguyenv/Postulate.Orm
        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);
            }
        }
コード例 #2
0
ファイル: Record.cs プロジェクト: manhnguyenv/Postulate.Orm
 /// <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);
 }
コード例 #3
0
ファイル: Record.cs プロジェクト: manhnguyenv/Postulate.Orm
 /// <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
 }
コード例 #4
0
ファイル: Record.cs プロジェクト: manhnguyenv/Postulate.Orm
 public virtual bool AllowDelete(IDbConnection connection, SqlDb <TKey> db, out string message)
 {
     message = null;
     return(true);
 }
コード例 #5
0
ファイル: Record.cs プロジェクト: manhnguyenv/Postulate.Orm
 /// <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
 }
コード例 #6
0
ファイル: Record.cs プロジェクト: manhnguyenv/Postulate.Orm
 /// <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
 }