IPrefetchPath2

Posts   
 
    
avgalex
User
Posts: 3
Joined: 24-Jul-2008
# Posted on: 13-Sep-2008 00:01:46   

Hello.

I the beginner in LLBlGen Pro

Do not prompt how truly to copy to help LLBlGen following sql script:

SELECT [IdPlan]
      ,[Id_disc]
      ,[Num_Term]
      ,[Lections]
      ,[Labor_work]
      ,[Pract_work]
      ,[Count_Examen]
      ,[Count_Zachet]
      ,[Count_KP]
      ,[Count_RGZ]
      ,[Count_KR]
      ,[Count_Kontr_Rab]
  FROM [diplom].[dbo].[Terms_Disc_Plan]
inner join [Plan] On  [Terms_Disc_Plan].[IdPlan] = [Plan].[Id_Plan]
inner join [Group_Plan] On  [Plan].[Id_Plan] = [Group_Plan].[id_Plan] 
where 
(([Num_Term] = 3 or [Num_Term] = 4)) and [Group_Plan].[id_group] = 132

I used

IPrefetchPath2 prefetchPath

and

SubPatch.Add

but then it is generated three queries and it is necessary to filter also in memory through

 IPredicate predicate = (TermsDiscPlanFields. NumTerm == term1 | TermsDiscPlanFields. NumTerm == term2)

with use EntityView2.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Sep-2008 03:36:30   

Hi there,

I don't understand you 100%. Could you please paste the full code you have for that purpose and what do you want to do. wink

Also, what LLBLGen version are you using? What TemplateSet (Adapter or SelfServicing) are you using?

David Elizondo | LLBLGen Support Team
avgalex
User
Posts: 3
Joined: 24-Jul-2008
# Posted on: 13-Sep-2008 09:10:35   

Version LLBLGen - 2.6 The version .Net Framework - 3.5 TemplateSet - Adapter

Method code:

  public static IEntityView2 GetDisiplines(GroupsEntity groupsEntity)
        {
             int kurs = GetKurs(groupsEntity.NameGroup);
             int term1 =  kurs * 2 - 1;
             int term2 =   kurs * 2; 
            using (var adapter = new DataAccessAdapter())
            {
                EntityCollection<GroupPlanEntity> entityCollection = new EntityCollection<GroupPlanEntity>();

                IRelationPredicateBucket filter = new RelationPredicateBucket();
              filter.PredicateExpression.Add(GroupPlanFields.IdGroup == groupsEntity.IdGroup);

                IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.GroupPlanEntity);
              prefetchPath.Add(GroupPlanEntity.PrefetchPathPlan).SubPath.Add(PlanEntity.PrefetchPathTermsDiscPlan);
            
                adapter.FetchEntityCollection(entityCollection, filter, prefetchPath);

                IPredicate predicate = (TermsDiscPlanFields.NumTerm == term1 | TermsDiscPlanFields.NumTerm == term2);
            IEntityView2 discView2 =  entityCollection[0].Plan.TermsDiscPlan.CreateView(predicate);

                return discView2; 
            }

Test code:

[Test]
          public void TestGetDisiplines()
          {
            GroupsEntity groupsEntity = new GroupsEntity(132);
             groupsEntity.NameGroup = "??-21";
             IEntityView2 listEntities = GroupGUI.GetDisiplines(groupsEntity); 
              Assert.AreEqual(listEntities.Count, 23);
          }

Generated SQL a code

exec sp_executesql N'SELECT DISTINCT [diplom].[dbo].[Group_Plan].[id_Group] AS [IdGroup], [diplom].[dbo].[Group_Plan].[id_Plan] AS [IdPlan] FROM [diplom].[dbo].[Group_Plan]  WHERE ( ( [diplom].[dbo].[Group_Plan].[id_Group] = @IdGroup1))',N'@IdGroup1 int',@IdGroup1=132
exec sp_executesql N'SELECT DISTINCT [diplom].[dbo].[Plan].[Id_Plan] AS [IdPlan], [diplom].[dbo].[Plan].[NamePlan], [diplom].[dbo].[Plan].[BeginPeriod], [diplom].[dbo].[Plan].[Speciality], [diplom].[dbo].[Plan].[FormEdu] FROM [diplom].[dbo].[Plan]  WHERE ( ( ( [diplom].[dbo].[Plan].[Id_Plan] = @IdPlan1)))',N'@IdPlan1 int',@IdPlan1=31

exec sp_executesql N'SELECT DISTINCT [diplom].[dbo].[Terms_Disc_Plan].[IdPlan], [diplom].[dbo].[Terms_Disc_Plan].[Id_disc] AS [IdDisc], [diplom].[dbo].[Terms_Disc_Plan].[Num_Term] AS [NumTerm], [diplom].[dbo].[Terms_Disc_Plan].[Lections], [diplom].[dbo].[Terms_Disc_Plan].[Labor_work] AS [LaborWork], [diplom].[dbo].[Terms_Disc_Plan].[Pract_work] AS [PractWork], [diplom].[dbo].[Terms_Disc_Plan].[Count_Examen] AS [CountExamen], [diplom].[dbo].[Terms_Disc_Plan].[Count_Zachet] AS [CountZachet], [diplom].[dbo].[Terms_Disc_Plan].[Count_KP] AS [CountKp], [diplom].[dbo].[Terms_Disc_Plan].[Count_RGZ] AS [CountRgz], [diplom].[dbo].[Terms_Disc_Plan].[Count_KR] AS [CountKr], [diplom].[dbo].[Terms_Disc_Plan].[Count_Kontr_Rab] AS [CountKontrRab] FROM [diplom].[dbo].[Terms_Disc_Plan]  WHERE ( ( ( [diplom].[dbo].[Terms_Disc_Plan].[IdPlan] = @IdPlan1)))',N'@IdPlan1 int',@IdPlan1=31

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 13-Sep-2008 16:29:22   

You requested all the entity types to be loaded thus 3 selects. You are creating a view only after everything is fetched into entities.

If you still insist to use a single SQL select than you have to use another way such as:

  • TypedList
  • Dynamic List
  • Database view
avgalex
User
Posts: 3
Joined: 24-Jul-2008
# Posted on: 13-Sep-2008 17:23:08   

Thanks for the answer. I have already copied a method by means of LINQ.