Idatabase is one of the main interfaces of fireasy. Data, which is similar to sqlhelper circulating on the Internet. However, idatabase only provides several highly cohesive methods, so you do not have to pass those dbcommands and dbparameter. Different database types provide classes that implement the iprovider interface to specify dbproviderfactory and various iproviderservice combinations to implement more functions.
Next, let's take a look at the idatabase and some interface combinations:
1. idatabase Interface
In fireasy. Data, idatabase is the underlying interface and provides the following attributes and methods:
Connectionstring: The connection string object of the database.
Provider: The implementation of different databases provided for idatabase is also an important interface, which will be described later.
Begintransaction: Start the Database Transaction and add the transaction lock. If the transaction has been started before idatabase, then calling this method will return false.
Committransaction: Submit a database transaction. If it matches the begintransaction method, it can be committed. Otherwise, false is returned.
Rollbacktransaction: Roll back the database transaction. If it matches the begintransaction method, it can be rolled back. Otherwise, false is returned.
Executedatatable: Execute a query statement to return the result as a datatable.
Executeenumerable: Execute a query statement to return the result in the T sequence. You can specify your idatarowmapper for conversion. defaultrowmapper is used by default.
Executenonquery: Execute a query statement to return the number of affected rows.
Executereader: Execute a query statement to return the result using idatareader.
Executescalar: Execute a query statement and return the first column of the first row.
Filldataset: Execute a query statement to populate the result with dataset.
Update: Save the changes to a able to the database.
2. iprovider Interface
Iprovider provides its implementation class for different database types. One of its main attributes is dbproviderfactory. Generally, database drivers are based on ADO. net, so they must provide their own dbproviderfactory. Dbproviderfactory is used to create instances such as dbconnection, dbcommand, and dbparameter.
In addition, iprovider provides a set of methods to facilitate the injection of some extended interfaces into the provider as a plug-in. Currently, the provided plug-in service interfaces include ibackupprovider, ibatcherprovider, isyntaxprovider, igeneratorprovider, ischemaprovider, icommandwatcher, and itranslateprovider.
Registerservice: Register a plug-in service instance. These instances must be iproviderservice interfaces.
Getservices: Obtain all registered plug-in instances.
Getservice: Get the specified type of plug-in service instance.
3. ibackupprovider Interface
This interface provides the database provider with database backup and recovery operations. Currently, it is only a prototype, and only MSSQL implements this interface.
Backup: Back up a specified database to a specified file.
Restore: Recover the database from the specified file.
4. ibatcherprovider Interface
This API supports batch data insertion for database providers. Most databases, such as MSSQL, MySQL, Oracle, and SQLite, provide the batch data insertion method. Therefore, you only need to implement this method to insert data in batches. In fireasy, batch insertion has been implemented for four database types. We will introduce them one by one later.
Insert: Write data from an entire able to the database in one or more batches.
5. isyntaxprovider Interface
This interface provides database providers with SQL Syntax Parsing support. As we all know, a length function may have different write methods in different databases. Therefore, isyntaxprovider provides parsing of three sets of syntax: String, date, and mathematical operation, there are also a variety of methods such as storage parameter prefix, field leading and post-guide, paging method, and data type conversion.
Stringsyntax: The parsing class of string functions. The methods in this class are not introduced anymore.
Datetimesyntax: The parsing class of the date function. The methods in this class are not introduced anymore.
Mathsyntax: The parsing class of mathematical operation functions. The methods in this class are not introduced anymore.
Identityselect: Obtain the query text of the recently created automatic number.
Segment: Use idatasegment to segment the SQL syntax and return the SQL statement after the segment syntax is added.
Convert: Convert a field to a specified data type, such as cast (name, nvarchar ).
Column: Generate the keyword of the corresponding data type. For example, generate nvarchar for dbtype. String in MSSQL.
Coalesce: If the source expression is null, the system judges the given set of parameters until a non-null parameter is returned. This is like var DB = str1? in C ?? Str2 ?? Str3.
6. ischemaprovider Interface
This interface provides the database provider with a query of the database architecture and returns metadata of such information as tables and fields.
Getschemas <t>: Obtains the schema information of the specified T type. t is implemented from ischemametadata, such as table, column, and procedure. You can use expressions to query the schema, such as getschemas <Table> (S => S. tablename = "product ").
Getschemas: This is the same as the method in dbconnection. a datatable is returned.
7. icommandwatcher Interface
This interface should have nothing to do with the database provider. It is only used in idatabase for external notifications when executing SQL statements.
Notify: External notificationProgramThe SQL statement executed and the time consumed.
8. itranslateprovider Interface
This interface provides the database provider with the resolution of the object LINQ query. You can write some LINQ queries and hand them over to this interface for resolution to get the SQL statements that can be executed by the database. Considering the complexity of this part, I will open several separate articlesArticle.
Fireasy. the underlying interfaces of data are mainly organized around idatabase and iprovider. To expand idatabase functions in the future, we only need to define a new interface to inherit from iproviderservice, then register in the corresponding provider. Of course, the provider configuration is also provided for convenient combination.
These are the underlying descriptions of fireasy. data. I don't know if you have a rough idea about fireasy. Data. Let's talk about your ideas.