Quick Save Entities with EF 7.0
namespace LibDataAccess {
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Data.Entity;
using Models;
using Microsoft.Data.Entity.Metadata;
public class MyDBContext : DbContext {
public MyDBContext Save<T>(T entity) where T : class {
this.Add<T>(entity: entity);
try {
this.SaveChanges();
} catch (Exception ex) {
throw;
}
return this;
}
public MyDBContext Save(object entity) {
this.Add(entity: entity);
try {
this.SaveChanges();
} catch (Exception ex) {
throw;
}
return this;
}
}