public virtual object Save <T, U>(T entity) where T : class, new() where U : IQuerySurface { IRepository <T> repository = null; ITable tbl = null; IQuerySurface database = Locator.Instance.GetEndPoint <U>(); try { tbl = database.Provider.FindOrCreateTable(typeof(T)); // TODO: this should be FindTable repository = GetRepository <T, U>(); } catch { } if (repository == null || tbl == null) { return(null); } var prop = entity.GetType().GetProperty(tbl.PrimaryKey.Name); // determine the pk field of the entities table. int primaryKeyValue; int.TryParse(prop.GetValue(entity, null).ToString(), out primaryKeyValue); // figure out the value of the pk if (primaryKeyValue > 0) { return(repository.Update(entity)); } return(repository.Add(entity)); }
public bool IsConnected <U>() where U : IQuerySurface { IQuerySurface Database = Locator.Instance.GetEndPoint <U>(); if (Database != null) { SqlConnection connection = new SqlConnection(Database.Provider.ConnectionString); try { connection.Open(); return(true); } catch { return(false); } finally { connection.Close(); connection.Dispose(); } } return(false); }
public SubSonicRepository(IQuerySurface db) { _db = db; }
public TestRepository(IQuerySurface db) { _db = db; _items = new List <T>(); }
public SimplestRepository(IQuerySurface db) : base(db) { }
private SubSonicRepository <T> GetRepository <T, U>() where T : class, new() where U : IQuerySurface { IQuerySurface db = Locator.Instance.GetEndPoint <U>(); return(new SubSonicRepository <T>(db)); }