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