describes how to work with databases and how database access

access to the database

Technology Flexberry the following methods access the database:

Note: ADO.NET НЕ ИСПОЛЬЗУЕТСЯ in projects in cases when you can do without it. Even if there is an urgent need to use ADO.NET one should check whether it is possible to do without it. Perhaps the use funcSQL.

If to speak about the applicability of possible methods of reading data: ADO.NET - use only in cases where not enough features of the data service.

a request in the service data

What constitutes the text of the SQL query generated by the service data:

If you look at what requests sends the service data to the server, then there are constants of type StormMainObjectKey and STORMJoinedMasterKey.

  • StormMainObjectKey - primary key (primarykey) of the object being read from the database. Constant StormMainObjectKey defined as ICSSoft.STORMNET.FunctionalLanguage.SQLWhere.SQLWhereLanguageDef.StormMainObjectKey.
  • STORMJoinedMasterKey. The organization of the proofreading of the database foreign keys are given names according to the type STORMJoinedMasterKey1. PstrfSTORMJoinedMasterKey` to use when constructing constraints in code not recommended, because their order may change.

ADO.NET

Below is an example of execution of SQL queries through technology ADO.Net:

public virtual decimal СуммаОплаченныхПокупок
{
	get
	{
		var connection = (SqlConnection)((SQLDataService)DataServiceProvider.DataService).GetConnection(); //get connection 
		var command = new SqlCommand("SELECT SUM(purchase.\"Amount\") "+
			"FROM \"Customer\" customer join \"Purchase\" purchase on customer.\"primaryKey\" = purchase.\"Buyer\" "+
			"WHERE purchase.\"Buyer\"=@Customer AND purchase.\"Status\" = \'Paid\' ", connection); //make a request 
		var parameter = new SqlParameter("@Customer", SqlDbType.UniqueIdentifier);
		parameter.Value = ((KeyGuid)this.__PrimaryKey).Guid; //define parameter values 
		command.Parameters.Add(parameter);
		
		try
		{
			connection.Open();
			var value = (decimal)command.ExecuteScalar(); //execution of query 
		}
		finally
		{
			connection.Close();
		}
		
		return value;
	}
	//... 
}
Переведено сервисом «Яндекс.Переводчик» http://translate.yandex.ru