Overriding a property of an abstract class?

Background: I use a class System.Data.Common.DBConnectto set classes that connect to various types of data sources, such as CSV, AD, SharePoint, SQL, Excel, SQL, etc. There is an interface that defines a contract for all types of data sources.

I wanted to use the connectionString property of a DBConnection object to store file paths in file sources to jump to methods GetData(DBConnection conn)for file-based file data sources. This does not work because when you assign a string, the ConnectionStribg property is created. My question is: How to create my own class derived from the DBConnection class (this is an abstract class) that ONLY ANNOUNCES a single ParameterString property?

TL; DR; I want to inherit from System.Data.Common.DBConnectand add my own string property. How?

EDIT

The interface is as follows:

public interface IDataImport
{
    DbConnection CreateDbConnection(params string[] connectionString);

    DataSet GetResults(DbConnection conn, params string[] strQuery);

    DataTable GetAvailableTables(DbConnection conn);

   DataTable GetAvailableFields(DbConnection conn, string tableName);

}
+3
source share
4 answers

You can inherit from DBConnection, but the problem is that you will need to implement all inherited abstract elements (of which 22):

public class MyConnect : DBConnection
{
   public string FilePaths{ get; set; }

   //Still need to implement all of the 
}

I assume that you really want to use the ADO built-in classes that handle the DBConnection implementation, so this is not a very good option.

Perhaps you just need to track the information separately. Is there a specific reason why information should be part of a join class?

You can do something line by line:

public class MyConnectionInfo
{
   public DBConnection Connection { get; set; }

   public string FileNames { get; set; }  
}

This will lead to a consolidation of information, but will not complicate the use of the DBConnection class.

+3

DbConnection , . :

protected override System.Data.Common.DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
{
    throw new System.NotImplementedException();
}

public override string ConnectionString
{
    get
    {
        throw new System.NotImplementedException();
    }
    set
    {
        throw new System.NotImplementedException();
    }
}

public override void ChangeDatabase(string databaseName)
{
    throw new System.NotImplementedException();
}

public override void Close()
{
    throw new System.NotImplementedException();
}

protected override System.Data.Common.DbCommand CreateDbCommand()
{
    throw new System.NotImplementedException();
}

public override string DataSource
{
    get { throw new System.NotImplementedException(); }
}

public override string Database
{
    get { throw new System.NotImplementedException(); }
}

public override void Open()
{
    throw new System.NotImplementedException();
}

public override string ServerVersion
{
    get { throw new System.NotImplementedException(); }
}

public override System.Data.ConnectionState State
{
    get { throw new System.NotImplementedException(); }
}

, , .

ConnectionString , . , , #.

+3

...

public abstract class MyClass:System.Data.Common.DBConnect 
{
    abstract String ParameterString
    {

        get; set;
    }   
}

, , , . ...

+2

RQDQ: , , , , :

public class GenericConnection
{
    public GenericConnection(){}

    public DbConnection DBConn { get; set; }

    public string Filename { get; set; }

}

, System.Data.Common.DBConnect , .

+1

All Articles