entityframework单例模式泛型用法
public class yms_Entity
{
private static T _instance;
public static readonly object SyncObject = new object();
public static T GetEntity()
{
if (_instance == null)
{
lock (SyncObject)
{
if (_instance == null)
{
_instance = (T)Activator.CreateInstance(typeof(T), true);
}
}
}
return _instance;
}
public static int SaveChanges
{
var entity = _instance as DbContext;
DbEntityEntry
if (rmEntry.State != EntityState.Modified)
{
rmEntry.State = EntityState.Modified;
}
else
{
entity.Set
}
return entity.SaveChanges();
}
public static void SetInstance(T value)
{
_instance = value;
}
}