How to inherit System.Data.SQLite in C #

I use System.Data.SQLite and C # to access SQLite databases / tables. For lazy and quick development reasons, I created my own class library to encapsulate some of the System.Data.SQLite methods in one method and to create many common database routines (methods) that allow me to reduce my work when accessing data.

If I inherited the System.Data.SQLite library instead of a link, it would help me optimize my work, is this possible? ¿Can you give an example, please?

+3
source share
2 answers

SQLite , SQLiteConnection. , , SQLite , SQLiteCommand SQLiteParameter, SQLite , . SQLiteFactory, ADO.NET SQLite.

. , ,

+1

, 7 ! ( ). .

using SQLite; // Here using sqlite-net-pcl
using System.Collections.Generic;

namespace SQLiteEx
{
  class SQLiteConnection : SQLite.SQLiteConnection
  {
    // Must provide a constructor with at least 1 argument
    public SQLiteConnection(string path)
      : base(path)
    {
    }

    // With this class, you can automatically append 
    // some kind of global filter like LIMIT 1000 
    string mGlobalFilter = "";
    public string GlobalFilter
    {
      set { mGlobalFilter = value; }
      get { return string.IsNullOrWhiteSpace(mGlobalFilter) ? "" : " " + mGlobalFilter; }
    }

    // You MUST constrain the generic type with "where T : new()"
    // OTHERWISE feel the wrath of:
    // ===================================================================
    //  'T' must be a non-abstract type with a public parameterless 
    //  constructor in order to use it as parameter 'T' in the generic 
    //  type or method 'SQLiteConnection.Query<T>(string, params object[])'
    // ===================================================================
    public List<T> Query<T>(string sql) where T : new()
    {
      return base.Query<T>(sql + GlobalFilter);
    }
  }
}
0

Source: https://habr.com/ru/post/1729083/


All Articles