what is Microsoft.Practices.EnterpriseLibrary.Data

你说的曾经没有我的故事 提交于 2019-12-03 16:44:35

问题


I want to know what is Microsoft.Practices.EnterpriseLibrary.Data and why we use this dll. what are the benefits of this dll.

I want to create a project on 3-tier architecture what is the best way for sql queries.

weather i use this dll or go for simple sqlcommand and dataadapter. currently i am working in this way: My Code in DAL File is:

public void Insert(long id)
{
    connection.Open();
    SqlCommand dCmd = new SqlCommand("test_procedure", connection);
    dCmd.CommandType = CommandType.StoredProcedure;
    try
    {
        dCmd.Parameters.AddWithValue("@id", id);           
        dCmd.ExecuteNonQuery();
    }
    catch
    {
        throw;
    }
    finally
    {
        dCmd.Dispose();
        connection.Close();
        connection.Dispose();
    }
}

I am confused weather i am working in right way or should i use Microsoft.Practices.EnterpriseLibrary.Data and then i create DatabaseFactory.


回答1:


The main advantage of the Microsoft.Practices.EnterpriseLibrary.Data library is that it makes it easier to produce database-agnostic code. The developer interacts mainly with more generic Database vs SqlConnection and DbCommand vs SqlCommand objects, in theory the mechanism of switching the underlying database, from MSSQL to Oracle becomes somewhat easier. Even though in my development experience I've never seen that occur.

Microsoft.Practices.EnterpriseLibrary.Data also directs the developer to use DbParameter for query parameters, which reduces the risk of SQL injection attacks.

The Microsoft.Practices.EnterpriseLibrary.Data is a higher abstract of the core ADO .Net constructs and enables the developer to complete the same tasks in a minimal amount of code.

If your learning Data access strategies I suggest continuing with ADO .Net the more you understand the basics the more useful Microsoft.Practices.EnterpriseLibrary.Data or Entity Framework or NHibernate is to use because you understand the fundamentals since the technologies are built on top of ADO .Net.



来源:https://stackoverflow.com/questions/14413514/what-is-microsoft-practices-enterpriselibrary-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!