Prefetch count

Posts   
 
    
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 10-Jun-2005 17:31:30   

I have the following code which prefecthes a couple of tables with no problems:

    Public Shared Function GetAssignmentByTeacherIdent(ByVal teacherIdent As Integer) As MedfordSchoolDistrict.Elementary.GradeBook.LLBL.HelperClasses.EntityCollection
        Dim Sorter As ISortExpression = New SortExpression
        Sorter.Add(SortClauseFactory.Create(Elementary.GradeBook.LLBL.AssignmentFieldIndex.DueDate, SortOperator.Ascending))
        Sorter.Add(SortClauseFactory.Create(Elementary.GradeBook.LLBL.AssignmentFieldIndex.Name, SortOperator.Ascending))

        Dim Filter As IRelationPredicateBucket = New RelationPredicateBucket

        Filter.PredicateExpression.Add(PredicateFactory.CompareValue( MedfordSchoolDistrict.Elementary.GradeBook.LLBL.AssignmentFieldIndex.TeacherIdent, ComparisonOperator.Equal, teacherIdent))

        Dim PrefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.AssignmentEntity, Integer))
        PrefetchPath.Add(AssignmentEntity.PrefetchPathGroupAssignment)
        PrefetchPath.Add(AssignmentEntity.PrefetchPathAssignmentSubSkill)

        GetAssignmentByTeacherIdent = New EntityCollection(New AssignmentEntityFactory)

        _Adapter.FetchEntityCollection(GetAssignmentByTeacherIdent, Filter, Nothing, Sorter, PrefetchPath)

        Return GetAssignmentByTeacherIdent
    End Function

I have another table called Score which has a FK from table AssignmentSubSkill. What I want is to add a prefetch that would also return the Count of Score for AssignmentSubSkill.

Is that possible to do with a prefetch and where would it store this Count value?

Thanks,

Fishy

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Jun-2005 12:12:31   

Prefetch score as well and add a FieldMappedOnRelatedField to AssignmentSubSkill which maps on Score.Count. simple_smile (or you can also simply do AssignmentSubSkill.Score.Count of course.

Frans Bouma | Lead developer LLBLGen Pro
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 12-Jun-2005 23:39:28   

Otis wrote:

Prefetch score as well and add a FieldMappedOnRelatedField to AssignmentSubSkill which maps on Score.Count. simple_smile (or you can also simply do AssignmentSubSkill.Score.Count of course.

But I don't want to fetch the Score records, just the count by assignmentSubSkill.

Thanks,

Fishy

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jun-2005 11:13:53   

Fishy wrote:

Otis wrote:

Prefetch score as well and add a FieldMappedOnRelatedField to AssignmentSubSkill which maps on Score.Count. simple_smile (or you can also simply do AssignmentSubSkill.Score.Count of course.

But I don't want to fetch the Score records, just the count by assignmentSubSkill.

Thanks, Fishy

That's not possible at the moment: you can't specify things like


select *, (SELECT COUNT (*) FROM Foo WHERE Bar=@bla) AS CountFoo FROM Table...

at the moment.

Frans Bouma | Lead developer LLBLGen Pro