En una publicación pasada mostré como usar EntLibDAAB configurándola usando el .config. En esta ocasión enseñaré como usar este componente usando solo C#.
Para esta demostración usé cualquier procedimiento almacenado que devuelva datos (en este caso dbo.uspGetEmployeeManagers) de una base de datos muy conocida llamada Adventure Works y un proyecto WPF con la siguiente class y DataGrid para mostrar los datos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
La primera forma de trabajar con EntLib6DAAB y SQL Server es usando directamente Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase y pasándole como argumento la cadena de conexión.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var employeeManagers = new List<EmployeeManager>();
var database = new Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase("Data source=.;User ID=sa; Password=sql; Initial Catalog=AdventureWorks2012");
using (var dataReader = database.ExecuteReader("dbo.uspGetEmployeeManagers", 81))
Si queremos tener un mayor control sobre la configuración podemos usar Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Si queremos usar alguna otra base de datos con EntLib como Oracle o MySQL tenemos que agregar nuevas entradas a ProviderMappings o si queremos establecer alguna base de datos por defecto no olvidemos hacer lo siguiente:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No hay comentarios.:
Publicar un comentario