Q
ダッパーの管理日
0
A
答えて
0
私は、RailsとDapperの両方で使用されていたデータベースを使って作業していました。 Railsはデータベースではなく、created_atとupdated_atを管理していました。だから.netアプリケーションでは、これらを管理するソリューションを実装しなければならず、イベントなどのこれらのレイヤーでビジネスロジックを追加する機能が提供されました。
私はこれをDapper Simple Crudのラッパーでどのように処理して挿入と更新を行うかの基本例を示しました。この例では、query、GET、Deleteなどの他の重要なメソッドをdapperやsimplecrudから公開することは含まれていません。あなたはそれらをあなたのdiscissionで公開する必要があります。安全のために
作成と更新のためにレコードをスタンプ
[Table("examples")]
public partial class example
{
[Key]
public virtual int id { get; set; }
[Required(AllowEmptyStrings = false)]
[StringLength(36)]
public virtual string name { get; set; }
[Dapper.IgnoreUpdate]
public virtual DateTime created_at { get; set; }
public virtual DateTime updated_at { get; set; }
}
public class ExampleRepository : IExampleRepository
{
private readonly IYourDapperWrapper db;
public PartnerRepository(IYourDapperWrapper yourDapperWrapper){
if (yourDapperWrapper == null) throw new ArgumentNullException(nameof(yourDapperWrapper));
db = yourDapperWrapper;
}
public void Update(example exampleObj)
{
db.Update(exampleObj);
}
public example Create(example exampleObj)
{
var result = db.Insert(exampleObj);
if (result.HasValue) exampleObj.id = result.value;
return exampleObj;
}
}
public class YourDapperWrapper : IYourDapperWrapper
{
private IDbConnectionFactory db;
public YourDapperWrapper(IDbConnectionFactory dbConnectionFactory){
if (dbConnectionFactory == null) throw new ArgumentNullException(nameof(dbConnectionFactory));
db = dbConnectionFactory;
}
public int Insert(object model, IDbTransaction transaction = null, int? commandTimeout = null)
{
DateUpdate(model, true);
var results = Db.NewConnection().Insert(model, transaction, commandTimeout);
if (!results.HasValue || results == 0) throw new DataException("Failed to insert object.");
return results;
}
public int Update(object model, IDbTransaction transaction = null, int? commandTimeout = null)
{
DateUpdate(model, false);
var results = Db.NewConnection().Update(model, transaction, commandTimeout);
if (!results.HasValue || results == 0) throw new DataException("Failed to update object.");
return results;
}
private void DateUpdate(object model, bool isInsert)
{
model.GetType().GetProperty("updated_at")?.SetValue(model, DateTime.UtcNow, null);
if (isInsert) model.GetType().GetProperty("created_at")?.SetValue(model, DateTime.UtcNow, null);
}
}
+0
例のおかげで@ザブブ – Rober
関連する問題
- 1. ダッパーとvarchars
- 2. ダッパーとサブクラス
- 3. 'yesterday'フィールドをDjangoの管理日リストフィルタ
- 4. KeystoneJS管理UIの日時フォーマット
- 5. 日付のバージョン管理と復元
- 6. Djangoの管理者フィルタは、日付のためのDjangoの管理者に
- 7. ダッパーとその状態
- 8. jquery fullcalendarサーバの日付としての管理日
- 9. Django管理者日付範囲フィルタ
- 10. SilverStripe - /管理者が一日か二日前のメモリ
- 11. Django管理者:データベース管理
- 12. C#(メモリ管理)の配列の管理
- 13. 未管理オブジェクトのメモリ管理
- 14. ASP.NET管理サイトの広告管理
- 15. JTextArea管理者のパスワード管理
- 16. Django:Custome管理サイトクラスの管理者用デコレータ
- 17. Avaya PBXのバージョン管理/設定管理?
- 18. リモートメソッド、リモート管理の集中管理
- 19. Grappelliの管理画面の日付ピッカーの週の開始
- 20. ユーザーの誕生日が秘密の場合の管理
- 21. Supress Today Djangoのリンク先の管理日ウィジェット
- 22. Djangoの管理日時のピッカーが動作しない
- 23. 管理インターフェースの日付ウィジェットの変更/適応
- 24. Mysql 5.7.11 - PHPクラスの空の日付を管理する方法
- 25. Djangoの管理日付フィールド-DateTimeField型混乱
- 26. Djangoモデルと管理者の日付範囲
- 27. バージョン管理/構成管理for Linuxイメージ
- 28. 自動変更管理/バージョン管理
- 29. 変更管理/構成管理
- 30. ワークフロー管理またはビジネスプロセス管理システム
日は、あなたがいずれかのあなたに、Dapperのを実装し、アプリケーションのより責任ある[Dapper.IgnoreUpdate]あなたは属性とプロパティのcreated_atモデルを飾ることを確認してくださいアプリケーションコードまたはSQLデータベースに格納されます。 Dapperはコードとデータベースの間のオブジェクトマッパーです。 SQLトリガー(https://weblogs.asp.net/jongalloway/adding-simple-trigger-based-auditing-to-your-sql-server-database)や監査証跡を作成する他のデータベース方法(http://stackoverflow.com/questions/17546601/best-way-to-implement-an-audit-trail-in-sql-server) –
ここでは、SQL Serverでそれを解決するためのいくつかの情報です。 http://stackoverflow.com/questions/17116334/sql-server-2008-row-insert-and-update-timestamps – JFM