Data Access Level (DAL)

I am using the .Net data access application block for a data library for my data access level.

In the DAL class of the class, I have methods like:

GetProductsInCategory (int CatId), GetAllProducts, GetCategories, etc.

My question is: where do I put this line of code?

DatabaseFactory.CreateDatabase("MyDB");

I have to put it in each method above or I will have a base class that will return the database object in my DAL class.

Also, should I store these DAL class methods as static?

+3
source share
3 answers

I prefer a base class that returns regular objects, such as a join, in your database.

: .NET Application Architecture:

Microsoft Enterprise Library. , . , , .

alt text

DataServiceBase , , , , .. , DataServiceBase . DataServiceBase , .

+3

ur..i DAL, DBManager. GetDatabase(), : return DatabaseFactory.CreateDatabase( "MyDB" ); :..

public DataSet GetProductsInCategory(int Category) 
{
Database db = base.GetDatabase(); 
DbCommand dbCommand = db.GetStoredProcComman("GetProductsByCategory"); 
db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, Category); 
return db.ExecuteDataSet(dbCommand);
} 

DAL ?

+1

I would suggest looking at using SubSonic to create DAL and create objects. It implements a block of Microsoft applications, but provides simple (and reliable) query capabilities, for example:

SubSonic.Query qry = new SubSonic.Query(Usr.Schema);
qry.SetSelectList(Usr.Columns.UserPkid);
qry.QueryType = SubSonic.QueryType.Select;
qry.AddWhere(Usr.UsernameColumn.ColumnName, SubSonic.Comparison.Equals, Username);

using (IDataReader reader = qry.ExecuteReader())
{
    while (reader.Read())
    {
        Trace.WriteLine("Fetched User Pkid [" + reader[Usr.Columns.UserPkid].ToString() + "]");
    }
}

And, of course, it implements the ActiveRecord template , so object classes have .Delete () ,. Add () ,. Get ().

0
source

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


All Articles