Beispiel #1
0
        public virtual T Create<T>(T TObject) where T : class
        {
            //ADD CREATE DATE IF APPLICABLE
            if (TObject is ICreatedOn)
            {
                (TObject as ICreatedOn).CreatedOn = DateTime.UtcNow;
            }

            //ADD LAST MODIFIED DATE IF APPLICABLE
            if (TObject is IModifiedOn)
            {
                (TObject as IModifiedOn).ModifiedOn = DateTime.UtcNow;
            }

            var newEntry = dbContext.Set<T>().Add(TObject);
            dbContext.SaveChanges();
            return newEntry.Entity; //https://entityframeworkcore.com/knowledge-base/48363894/where-is-idbset-t--in-entity-core //https://q.cnblogs.com/q/89456/
        }
 /// <summary>
 /// Inserts a single object to the database and commits the change
 /// </summary>
 /// <remarks>Synchronous</remarks>
 /// <param name="t">The object to insert</param>
 /// <returns>The resulting object including its primary key after the insert</returns>
 public TObject Add(TObject t)
 {
     _context.Set <TObject>().Add(t);
     _context.SaveChanges();
     return(t);
 }