示例#1
0
    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));
    }
示例#2
0
    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);
    }
示例#3
0
 public SubSonicRepository(IQuerySurface db)
 {
     _db = db;
 }
 public TestRepository(IQuerySurface db)
 {
     _db    = db;
     _items = new List <T>();
 }
示例#5
0
 public SimplestRepository(IQuerySurface db) : base(db)
 {
 }
示例#6
0
    private SubSonicRepository <T> GetRepository <T, U>() where T : class, new() where U : IQuerySurface
    {
        IQuerySurface db = Locator.Instance.GetEndPoint <U>();

        return(new SubSonicRepository <T>(db));
    }