TypedView and DefineField?

Posts   
 
    
Ganesh
User
Posts: 28
Joined: 18-May-2005
# Posted on: 11-Jul-2005 23:15:28   

I am using a TypedView in a Dynamic Typed List. If had to have a alias column name and alias TypedView name, it just does'nt work. It gives errors.

fields.DefineField(NameFormatViewFieldIndex.FirstMiddleLastSuf, 0,"StudentName");

I get...

Argument '3': cannot convert from 'string' to 'SD.LLBLGen.Pro.ORMSupportClasses.AggregateFunction'

Have AliasName for the TypedView...

fields.DefineField(NameFormatViewFieldIndex.FirstMiddleLastSuf, 17, "RoommateName","NameFormatViewRoommate");

but I get the following error...

The best overloaded method match for 'Jenzabar.ERP.EX.Data.HelperClasses.ResultsetFields.DefineField(Jenzabar.ERP.EX.Data.AddressMasterFieldIndex, int, string, string)' has some invalid arguments

What am I missing, OR Is the TypedView have some restrictions?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 10:28:02   

I'm not sure what you're trying to do. You're trying to build a dynamic list based on a view? You can't / don't have to specify a field alias, as a view doesn't have relations, so you can just add the fields in a single typed view to a dynamic list, so no aliases are required.

Frans Bouma | Lead developer LLBLGen Pro
Ganesh
User
Posts: 28
Joined: 18-May-2005
# Posted on: 12-Jul-2005 16:22:14   

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);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 17:10:36   

The limitation is as I described: typed views don't have relations, so will never end up in a join so aliassing won't be necessary.

If I were you, I'd map an entity on the view, define the relation in the designer and then regenerate the code. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Ganesh
User
Posts: 28
Joined: 18-May-2005
# Posted on: 12-Jul-2005 20:21:11   

If I were you, I'd map an entity on the view, define the relation in the designer and then regenerate the code. stuck_out_tongue_winking_eye

Even If I do so, When I use the DefineField for TypedView, I may not able to assign the alias name since I will be having the relation with the same view twice OR I am not getting what you are saying?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 20:51:46   

No, you then use the DefineField for the entity mapped onto the view, which does have the alias possibility simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Ganesh
User
Posts: 28
Joined: 18-May-2005
# Posted on: 12-Jul-2005 21:10:00   

Frans, Could you please throw me an example where an Entity A and Entity B is having a relation with TypedView T and would like to get the Attributes of TypedViews in the Dynamic TypedList?. Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 21:33:30   

Add an entity Tv which is mapped on the view on which T is also mapped. Then create relations between A and Tv, B and Tv (if applicable of course).

Then generate code.

You then can add A's fields, B's fields and Tv's fields using DefineField() and also specify aliasses. This is because Tv is an entity, not a typed view.

Frans Bouma | Lead developer LLBLGen Pro
Ganesh
User
Posts: 28
Joined: 18-May-2005
# Posted on: 12-Jul-2005 21:40:37   

Thats what exactly I did to resolve the alias problem, I deleted the TV and Added in as Entity and that worked, what now I am wondering is should I stay away from putting Views in TVs instead in Entitys directly, Only confusion that causes is a distinction between regular entity and a View though.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 22:29:00   

Use a typed view if you want to fetch that view and show it as a list/use it as a list.

Map an entity on a view if you want to use that view in relations with entities or other views (on which you then also map an entity).

That works best and saves you from writing the code for the custom relations you now have to create in code.

Frans Bouma | Lead developer LLBLGen Pro
Benno
User
Posts: 3
Joined: 12-Aug-2005
# Posted on: 12-Aug-2005 14:32:32   

Hi Otis,

Otis wrote:

Map an entity on a view if you want to use that view in relations with entities or other views (on which you then also map an entity)...

This may sound like a stupid question to LLBLGen veterans but I cannot seem to be able to achieve that...?!

Would you mind briefly explain how I could do that ?!

FYI, the database view I am trying to add (as Entity) or somehow link to en existing obtains data from another SQL Server database... All Entities seem to be only based on database tables...?!

Thank you,

Ben

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Aug-2005 15:23:42   

This is similar to the other question you asked in architecture: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3684 ? simple_smile

You need 1.0.2004.2 to map an entity onto a view. After that, you can use the ENTITY mapped on the view to create relations between that entity and other entities. To avoid having two times the same conversation, I'd suggest we continue in one of the two threads, this one or the other simple_smile (you decide simple_smile )

Frans Bouma | Lead developer LLBLGen Pro
Benno
User
Posts: 3
Joined: 12-Aug-2005
# Posted on: 15-Aug-2005 17:09:46   

Hi Otis,

This is similar to the other question you asked in architecture

It is... Trying to maximise my chances to get a prompt answer !! DId know you kept such a close eye on posts !! simple_smile

You need 1.0.2004.2 to map an entity onto a view.

That explains why I could find a way !! I run 1.0.2004.1.

I can only find the download for a Demo on your site... If I have a license, should I install the demo instead ?

I am not managing licenses or updates for the organisation I work and I was not advise of a licensed-update for 1.0.2004.2...

Could you advise as to the the best course of actions to upgrade ?!

After that, you can use the ENTITY mapped on the view to create relations between that entity and other entities.

Sounds simple enough...

Thank you,

Ben

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Aug-2005 18:47:46   

Benno wrote:

This is similar to the other question you asked in architecture

It is... Trying to maximise my chances to get a prompt answer !! DId know you kept such a close eye on posts !! simple_smile

simple_smile

You need 1.0.2004.2 to map an entity onto a view.

That explains why I could find a way !! I run 1.0.2004.1.

I can only find the download for a Demo on your site... If I have a license, should I install the demo instead ?

I am not managing licenses or updates for the organisation I work and I was not advise of a licensed-update for 1.0.2004.2...

Could you advise as to the the best course of actions to upgrade ?!

No the demo won't work in that situation, the demo only works with demo licenses. What you should do is log into the customer area (ask the license manager for the customerid/password or let him/her do it for you) and go to the upgrades section and download the latest installer (first item in the list).

Then, go to the documentation section and download the latest documentation as well. Open the documentation, and go to the 'migrating your code' section and read it. As you're on 1.0.2004.2, the migration should be smooth. 1) create a copy of the llblgen pro installation folder if you aren't sure, so you can go back 2) uninstall llblgen pro, and reinstall the new installer 3) create a copy of your generated code 4) load your project and re-generate the code. 5) make sure ALL your projects in your solution are referencing the new 1.0.2004.2 assemblies 6) recompile everything.

You're now in 1.0.2004.2 simple_smile

Frans Bouma | Lead developer LLBLGen Pro