Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Jun 2

Written by: Steve Gray
6/2/2010 10:46 AM  RssIcon

This is new functionality in the Enterprise Library 5.0 Data Access Application Block, the ability to create a class (typically this mirrors a table), and then write a stored procedure and send the results of the stored proc directly to the class… no looping or enumerating.

This is a complete code example, if you’ll copy all this into your environment it’ll run.

First the stored proc:

IF EXISTS (
  SELECT * 
    FROM INFORMATION_SCHEMA.ROUTINES 
   WHERE SPECIFIC_SCHEMA = N'dbo'
     AND SPECIFIC_NAME = N'FP_SOP10100_SEL_byID' 
)
   DROP PROCEDURE dbo.FP_SOP10100_SEL_byID
GO
CREATE PROCEDURE dbo.FP_SOP10100_SEL_byID      
      
@sopnumbe varchar(31),      
@soptype smallint      
      
AS      
select convert(int,2) as SOPTYPE 
GO
GRANT exec on FP_SOP10100_SEL_byID to public
  

 

Note that no real data access is involved, the proc returns a constant. Now the VB code:

Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim db As Database
            db = EnterpriseLibraryContainer.Current.GetInstance(Of Database)("TWO")
            Dim rowmapper As IRowMapper(Of SOP10100)
            rowmapper = MapBuilder(Of SOP10100).MapNoProperties _
                .Map(Function(x) x.SOPTYPE).ToColumn("SOPTYPE") _
                .Build()
            Dim s = db.ExecuteSprocAccessor(Of SOP10100)("dbo.FP_SOP10100_SEL_byID", rowmapper, "ORDST2225", 2).SingleOrDefault
            MsgBox(s.SOPTYPE)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Me.Close()
    End Sub
End Class
Public Class SOP10100
    Public Property SOPTYPE As Int32 = 1
End Class

 

The example above uses a ‘row mapper’, not strictly needed because our stored procedure has one column (SOPTYPE) and the class has one property (SOPTYPE). The example below is the same thing, without the mapper

Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim db As Database
            db = EnterpriseLibraryContainer.Current.GetInstance(Of Database)("TWO")
            Dim s = db.ExecuteSprocAccessor(Of SOP10100)("dbo.FP_SOP10100_SEL_byID", "ORDST2225", 2).SingleOrDefault
            MsgBox(s.SOPTYPE)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
Public Class SOP10100
    Public Property SOPTYPE As Int32 = 1
End Class

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us