我正在使用通用Repository和UnitOfWork模式來處理數據庫。設置Generic Repository中的列的值
現在我有如下的插入方法:
public virtual void Insert(TEntity entity)
{
//How to set up like this
entity.UpdatedDate = DateTime.Now.AddMonth(-1);
entity.ObjectState = ObjectState.Added;
_dbSet.Attach(entity);
_context.SyncObjectState(entity);
}
的實體是代表了一個表類,像這樣:
public partial class AM_User
{
public int UserID { get; set; }
public string UserName { get; set; }
public Nullable<System.DateTime> CreatedDate { get; set; }
public Nullable<System.DateTime> UpdatedDate { get; set; }
}
實體有一個名爲CreatedDate
列。我只想要一個地方輸入CreatedDate的值?我怎麼能使用反射器來設置它的價值?
這部分代碼真的很有幫助。 – gdmanandamohon