A sample (in Vb.Net). The method to fill the Grid is below and the DTO for
the grid follows. The lambda function is the selPartner line below.
Private Sub BuildDataGridPartnerContribution(ByVal ID As Integer)
Dim _service As IContributionAmountService = New
ContributionAmountService(_caAmtRep, _unitOfWork)
Dim _list As New List(Of ContributionAmount)
Dim _query As New Query
Dim _grdList As IEnumerable(Of PartnerContributionGrid)
Dim _partnerSvc As IPartnerService = New PartnerService(_partnerRep,
_projParticipantsRep, _unitOfWork)
Dim _partnerList As New List(Of Partner)
_query.Criteria.Add(New Criteria("CaDetailID", ID, CriteriaOperator.Equals))
_query.Criteria.Add)New Criteria("CommitmentTypeID",
CommitmentType.COMMITMENT_TYPE_ELIG_COST, CriteriaOperator.Equals))
_unitOfWork.BeginTransaction()
_partnerList = _partnerSvc.FindAll()
_list = _service.FindBy(_query).ToList
_unitOfWork.Commit()
Dim selPartner As Func(Of Decimal?, Boolean) = Function(x) x IsNot Nothing
_grdList = (From myPartner in _partnerList _
Join myCaAmount in _list _
On myPartner.Id Equals myCaAmount.PartnerID
Select New PartnerContributionGrid With { _
.CaDetailID = myCaAmount.CaDetailID, .PartnerID =
myCaAmount.PartnerID, _
.CaParticipantID = myCaAmount.CaParticipantID,
.PartnerENM = myPartner.EnglishName, _
.PartnerFNM = myPartner.FrenchName,
.PartnerSelected = selPartner(myCaAmount.ContributionAmount), _
.PartnerAmount = String.Format("{0:C2}",
myCaAmount.ContributionAmount)}) _
.Union(From myPartner in _partnerList _
Where Not (From myCaAmount in _list Select
myCaAmount.PartnerID).Contains(myPartner.ID) _
Select New PartnerContributionGrid With {
.CaDetailID = ID, .PartnerID = myPartner.Id, _
.CaParticipantID = 0,
.PartnerENM = myPartner.EnglishName, _
.PartnerFNM =
myPartner.FrenchName, .PartnerAmount = "", _
.PartnerSelected = False})
_localView.BindPartnerContributionGrid(_grdList)
_service = Nothing
_partnerSvc = Nothing
_partnerList = Nothing
_list = Nothing
_grdList = Nothing
_query = Nothing
End Sub
Public Class PartnerContributionGrid
Private _caDetailID As Integer
Private _partnerID As Integer
Private _caParticipantID As Integer
Private _partnerENM As String
Private _partnerFNM As String
Private _partnerSelected As Boolean
Private _partnerAmount As String
Public Property CaDetailID() As Integer
Get
Return _caDetailID
End Get
Set(ByVal value As Integer)
_caDetailID = value
End Set
End Property
Public Property PartnerID() As Integer
Get
Return _partnerID
End Get
Set(ByVal value As Integer)
_partnerID = value
End Set
End Property
Public Property CaParticipantID() As Integer
Get
Return _caParticipantID
End Get
Set(ByVal value As Integer)
_caParticipantID = value
End Set
End Property
Public Property PartnerENM() As String
Get
Return _partnerENM
End Get
Set(ByVal value As String)
_partnerENM = value
End Set
End Property
Public Property PartnerFNM() As String
Get
Return _partnerFNM
End Get
Set(ByVal value As String)
_partnerFNM = value
End Set
End Property
Public Property PartnerSelected() As Boolean
Get
Return _partnerSelected
End Get
Set(ByVal value As Boolean)
_partnerSelected = value
End Set
End Property
Public Property PartnerAmount() As String
Get
Return _partnerAmount
End Get
Set(ByVal value As String)
_partnerAmount = value
End Set
End Property
End Class
On Wed, Jun 23, 2010 at 11:21 PM, Mike <[email protected]> wrote:
> Can you possibly provide an example? I'm not sure I'm following you.
>
> On Jun 23, 5:44 pm, John Davidson <[email protected]> wrote:
> > The approach I use to do similar tasks is to do a series of simple
> queries,
> > where the first query provides an array of fk for the next query and use
> an
> > 'In' criteria on the second query. This proceeds for each query in turn
> > until I have all the data. Then I build a LINQ-for-Objects query based on
> > the fetch data.
> >
> > Domain logic is encapsulated in various lambda equations and they are
> used
> > in the LINQ-for-Object query that all runs in memory. The LINQ query then
> > selects the fields required to fill the DTO that is passed to the grid.
> >
> > John Davidson
> >
> >
> >
>
> > On Wed, Jun 23, 2010 at 6:05 PM, Mike <[email protected]> wrote:
> > > I'm trying to figure out how to do complicated queries in NHibernate.
> > > I'm trying to refactor a Stored Proc that populates a grid to an
> > > NHibernate query, but I'm having problems because it joins a dozen
> > > tables. I'm aware of setting FetchModes in NHibernate; however, it
> > > just seems like it's going to be difficult to recreate the results of
> > > this query in OO format instead of tabular format. Here's an example
> > > query:
> >
> > > SELECT
> > > Book.ID,
> > > Book.Name,
> > > Author.Name,
> > > AuthorAddress.State,
> > > Publisher.Name,
> > > PublisherAddress.State
> > > FROM
> > > Book
> > > INNER JOIN Author ON (Author.ID = Book.AuthorID)
> > > INNER JOIN Address AuthorAddress ON (AuthorAddress.ID =
> > > Author.AddressID)
> > > INNER JOIN Publisher ON (Publisher.ID = Book.PublisherID)
> > > INNER JOIN Address PublisherAddress ON (PublisherAddress.ID =
> > > Publisher.AddressID)
> >
> > > Now this is a mocked up example, but you can see the Joins go more
> > > than one level deep. After I figure in dynamic sorting and paging,
> > > the Stored Proc yields the exact structure I want to show in my grid.
> > > I'm having problems replicating this with NHibernate. Any advice out
> > > there? Should I be taking a different approach? I thought about
> > > keeping a stored procedure and loading it to a simple DTO for display
> > > in my grid, but there's domain logic I would love to include in the
> > > grid, and I'd hate to replicate it.
> >
> > > Thanks!
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "nhusers" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
>
> > > [email protected]<nhusers%[email protected]>
> <nhusers%[email protected]<nhusers%[email protected]>>
>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.