How to get a handle on a SQL view

Posts   
 
    
avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 19-Dec-2007 21:27:40   

I have a budgetfeesByProjID view in sql.

I have the Typedviewclass of budgetfeesview. I'm a little confused on how to access and filter. This is what I'm trying to do. Get the rows where ID = '1' and IsActive='True' then perform this function. Sum(hours*SellRate)

This is what I have so far..

Imports PBDAL.TypedViewClasses Imports PBDal.HelperClasses Imports SD.LLBLGen.Pro.ORMSupportClasses Dim ProjectProfileID as String

Dim internalFees As New BudgetFeesByProjIdTypedView() Dim FeesFilter As IPredicateExpression = New PredicateExpression(New FieldCompareValuePredicate(????????, ComparisonOperator.Equal, Me.ProjectProfileID)) InternalFees.Fill()

Can someone guide me in the right direction?

tx av

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 19-Dec-2007 22:37:14   

You should set the entity fieldindex on the ?????? position, e.g. CustomerFieldIndex.CustomerName.

You should also pass the predicate as a parameter to the fill method.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Dec-2007 09:01:57   

Please check the manual's section "Using the gGenerated code -> SelfServicing/Adapter -> Using TypedViews, TypedLists and Dynamic Lists -> Using the typed view classes"

avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 15:25:58   

I've looked in the documentation. That's why I'm not sure what to do. You only have a snippet of code and not a full example which is why I'm not sure how to implement.

How do I know what field is the field index?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Dec-2007 15:38:18   

The code example is simple but that's all what you have to do:

InvoicesTypedView invoices = new InvoicesTypedView();
IPredicateExpression invoicesFilter = new PredicateExpression(InvoicesFields.OrderID > 11000));
invoices.Fill(0, null, true, invoicesFilter);

Would you please post the SQL query that you want to execute against the View?

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 20-Dec-2007 15:40:24   

you don't have to know the index of the field, that's been taken care of by LLBLGen (internal enum). This value is at runtime converted to a fieldname on creation of the SQL statement. So, you shouldn't worry about that...

avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 15:50:51   

Here is my code: Dim internalFees As New BudgetFeesByProjIdTypedView() Dim FeesFilter As IPredicateExpression = New PredicateExpression(New FieldCompareValuePredicate(InternalFeesFields.ProjProfID, ComparisonOperator.Equal, Me.ProjectProfileID)) internalFees.Fill()

I get an error on InternalFeesFields.ProjProfID

InternalFeesFields is not declared.

avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 15:59:59   

Here is the SQl query I'm will be doing

Select Sum(Hours * SellRate) as FeesTotal From vw_BudgetFeesByProjID where ProjProfID ='1'and isActive='True'

DvK
User
Posts: 323
Joined: 22-Mar-2006
# Posted on: 20-Dec-2007 16:25:10   

use InternalFeesFieldIndex.ProjProfID instead of InternalFeesFields.ProjProfID ?? No....that's not gonna work here.... :-)

USE :

Dim FeesFilter As New PredicateExpression(InternalFeesFields.ProjProfID = Me.ProjectProfileID)

And then pass this predicate to the Fill method.

avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 16:29:23   

Oh for heavens sake, a typo on my part. I guess I should leave for x-mas vacation now. Thank you very much for your help!!

avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 16:30:42   

I spoke too soon. I'm still getting InternalFeesFIeldIndex is not declared.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Dec-2007 16:36:27   

Please try the following code:

Dim internalFees As New BudgetFeesByProjIdTypedView()
Dim FeesFilter As IPredicateExpression = New PredicateExpression(New FieldCompareValuePredicate(BudgetFeesByProjIdFields.ProjProfID, ComparisonOperator.Equal, Me.ProjectProfileID))
internalFees.Fill(0, null, true, FeesFilter )
avarndel
User
Posts: 36
Joined: 14-Jun-2007
# Posted on: 20-Dec-2007 16:42:46   

That worked. Now how do I get a handle on the results?

so that I can do some manipulation with the data

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Dec-2007 10:58:43   

internalFees should contain the resultSet, it is a dataTable.