My requirement is to have a TypedView part of the Join TWICE and I have to have a aliasEntity name for one, so I did that in the relations, but in the DefineFields its not letting me to do so for TypedView until otherwise I make the TypedView as Entity in LLBLGen project itself. (For I did remove my TypedView and added as Entity in our project!).
The following code works only when NameFormatViewFieldIndex is an Entity and not an TypedView....Why this limitation is?
IDataAccessAdapter adapter = DataAccessAdapterFactory.GetDataAdapter();
ResultsetFields fields = new ResultsetFields(21);
fields.DefineField(NameFormatViewFieldIndex.FirstMiddleLastSuf,0,"StudentName");
fields.DefineField(RoomAssignFieldIndex.BldgLocCde, 1, "RoomAssignLocation");
fields.DefineField(RoomAssignFieldIndex.BldgCde, 2, "RoomAssignBuilding");
fields.DefineField(LocationMasterFieldIndex.LocDesc, 3, "Location");
fields.DefineField(BuildingMasterFieldIndex.BuildingDesc, 4, "Building");
fields.DefineField(RoomAssignFieldIndex.RoomCde, 5, "Room");
fields.DefineField(RoomAssignFieldIndex.RoomType, 6, "RoomType");
fields.DefineField(StudSessAssignFieldIndex.CampusBoxNum, 7, "CampusBoxNum");
fields.DefineField(AddressMasterFieldIndex.AddrCde, 8, "MailingAddressCode");
fields.DefineField(AddressMasterFieldIndex.AddrLine1, 9, "AddressLine1");
fields.DefineField(AddressMasterFieldIndex.AddrLine2, 10, "AddressLine2");
fields.DefineField(AddressMasterFieldIndex.AddrLine3, 11, "AddressLine3");
fields.DefineField(AddressMasterFieldIndex.City, 12, "City");
fields.DefineField(AddressMasterFieldIndex.State, 13, "State");
fields.DefineField(AddressMasterFieldIndex.Zip, 14, "Zip");
fields.DefineField(AddressMasterFieldIndex.Phone, 15, "Phone");
fields.DefineField(StudRoommatesFieldIndex.RoommateId, 16, "RoommateID");
fields.DefineField(NameFormatViewFieldIndex.FirstMiddleLastSuf, 17, "RoommateName","NameFormatViewRoommate");
fields.DefineField(AddressMasterFieldIndex.AddrCde, 18, "EmailAddressCode","AddressMasterRoommate");
fields.DefineField(AddressMasterFieldIndex.AddrLine1, 19, "RoommateEmail","AddressMasterRoommate");
fields.DefineField(CmSessionMstrFieldIndex.SessDesc, 20, "SessionDescription");
IRelationPredicateBucket bucket = new RelationPredicateBucket();
// define custom relation self-joined
IEntityRelation CustomRelationA = new EntityRelation(RelationType.OneToOne);
CustomRelationA.AddEntityFieldPair(EntityFieldFactory.Create(StudSessAssignFieldIndex.IdNum),
EntityFieldFactory.Create(NameFormatViewFieldIndex.IdNum));
// add this as a relation
bucket.Relations.Add(CustomRelationA,JoinHint.Inner);
// define custom relation left-outer-joined
IEntityRelation CustomRelationB = new EntityRelation(RelationType.OneToMany);
CustomRelationB.AddEntityFieldPair(EntityFieldFactory.Create(StudSessAssignFieldIndex.IdNum),
EntityFieldFactory.Create(AddressMasterFieldIndex.IdNum));
// add this as a relation
bucket.Relations.Add(CustomRelationB,JoinHint.Right);
// StudSessAssign left outer Joins with Stud_Roommates
bucket.Relations.Add(StudSessAssignEntity.Relations.StudRoommatesEntityUsingSessCdeIdNum,JoinHint.Left);
// define custom relation Left-Outer-joined
IEntityRelation CustomRelationC = new EntityRelation(RelationType.ManyToOne);
CustomRelationC.AddEntityFieldPair(EntityFieldFactory.Create(NameFormatViewFieldIndex.IdNum),
EntityFieldFactory.Create(StudRoommatesFieldIndex.RoommateId));
// add this as a relation
bucket.Relations.Add(CustomRelationC,"NameFormatViewRoommate",JoinHint.Left);
// define custom relation left-outer-joined
IEntityRelation CustomRelationD = new EntityRelation(RelationType.ManyToOne);
CustomRelationD.AddEntityFieldPair(EntityFieldFactory.Create(AddressMasterFieldIndex.IdNum),
EntityFieldFactory.Create(StudRoommatesFieldIndex.RoommateId));
// add this as a relation
bucket.Relations.Add(CustomRelationD,"AddressMasterRoommate",JoinHint.Left);
bucket.Relations.Add(StudSessAssignEntity.Relations.RoomAssignEntityUsingSessCdeIdNum, JoinHint.Left);
bucket.Relations.Add(RoomAssignEntity.Relations.LocationMasterEntityUsingBldgLocCde, JoinHint.Left);
bucket.Relations.Add(RoomAssignEntity.Relations.BuildingMasterEntityUsingBldgCde, JoinHint.Left);
// cm_session_mstr joins with stud_sess_assign
bucket.Relations.Add(StudSessAssignEntity.Relations.CmSessionMstrEntityUsingSessCde, JoinHint.Inner);
// WHERE class
IPredicateExpression A = new PredicateExpression();
A.Add(PredicateFactory.CompareValue(StudRoommatesFieldIndex.ReqActualFlag, ComparisonOperator.Equal, "A"));
A.AddWithOr(new FieldCompareNullPredicate(EntityFieldFactory.Create(StudRoommatesFieldIndex.RoommateId),null,false));
//Add where criteria to the bucket
bucket.PredicateExpression.Add(A);
IPredicateExpression B = new PredicateExpression();
B.Add(PredicateFactory.CompareValue(AddressMasterFieldIndex.AddrCde, ComparisonOperator.Equal, strResidenceLifeMailingAddress));
B.AddWithOr(new FieldCompareNullPredicate(EntityFieldFactory.Create(AddressMasterFieldIndex.AddrCde),null));
bucket.PredicateExpression.AddWithAnd(B);
IPredicateExpression C = new PredicateExpression();
C.Add(PredicateFactory.CompareValue(AddressMasterFieldIndex.AddrCde, ComparisonOperator.Equal, strResidenceLifeEmailAddress,"AddressMasterRoommate"));
C.AddWithOr(new FieldCompareNullPredicate(EntityFieldFactory.Create(AddressMasterFieldIndex.AddrCde),null,"AddressMasterRoommate"));
bucket.PredicateExpression.AddWithAnd(C);
IPredicateExpression D = new PredicateExpression();
D.Add(PredicateFactory.CompareValue(StudSessAssignFieldIndex.IdNum, ComparisonOperator.Equal, idNum));
bucket.PredicateExpression.AddWithAnd(D);
// Add the "ORDER BY" clause cm_session_mstr.sess_end_dte desc
ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(CmSessionMstrFieldIndex.SessEndDte, SortOperator.Descending));
DataTable dynamicList = new DataTable();
adapter.FetchTypedList(fields, dynamicList,bucket, 0, sorter, true, null);