Alias Translation problem in the select clause

Posts   
 
    
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 21-Sep-2006 19:56:34   

Is there a way to know what will be the alias name after the LLBLGen conversion!

I'm asking that because we are creating a function expression that concatenate 2 fields together and the aliases (on those fields) are not converted to the LLBLGen ones.

Could we do, the translation, in the function expression class (ToQueryText method)?

Can you help me?

Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 21-Sep-2006 20:51:40   

I forgot i'm using selfservicing....

Could this function be useful?...

base.DatabaseSpecificCreator.CreateFieldName(????, field.SourceObjectName, field.ObjectAlias, ???);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Sep-2006 21:00:48   

Could you give an example, I have no clue what you're requesting, sorry flushed

Frans Bouma | Lead developer LLBLGen Pro
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 21-Sep-2006 21:19:44   

Ok I'm using a custom query with aliases. When I look at the generated sql all the aliases are changed... like...A become.. "LPA_T1"... So you must convert my aliases somewhere at some point to something else.

I want access to the function that converts the field aliases because I'm building custom Expressions (concatenate fields with aliases)... and I want to apply the alias translation by hand myself.

I hope this helps

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 16:40:44   

Banane wrote:

Ok I'm using a custom query with aliases. When I look at the generated sql all the aliases are changed... like...A become.. "LPA_T1"... So you must convert my aliases somewhere at some point to something else.

I want access to the function that converts the field aliases because I'm building custom Expressions (concatenate fields with aliases)... and I want to apply the alias translation by hand myself.

I hope this helps

AH ok. simple_smile That's done in the database specific DbSpecificCreator.FindRealAlias. The routine is located in DbSpecificCreatorBase.cs. simple_smile

Every DQE has its own specific creator. This routine is scope specific, so if you define a new alias in a subscope (subquery for example) it can handle that.

Frans Bouma | Lead developer LLBLGen Pro
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 22-Sep-2006 17:46:37   

I'm already using it....but it does not translate the alias...

I have tryed this as well...



 // in ToQueryText of my Concat. oracle function
// my alias is A
// IN the other select that gets changed or translated to LPA_T1

string fieldName = this.DatabaseSpecificCreator.CreateFieldName(field,field.SourceColumnName, field.ObjectAlias, "");


but this still does not work :-(

Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 22-Sep-2006 18:09:41   

Here is an exemple of the generated SQL

You can see in the select we are using FromUserName and in the FROM it has been translated to LPA_F2 !!

You can also see that we are using the same table!


SELECT 
     FromUserName"."FIRST_NAME"||' '||"FromUserName"."LAST_NAME"    AS "AssignedByUser",  
     ToUserName"."FIRST_NAME"||' '||"ToUserName"."LAST_NAME AS "AssignedToUser", ...

FROM  
   "AMSOBJ"."SECURITY_USERS" "LPA_F2", 
   "AMSOBJ"."SECURITY_USERS" "LPA_T1"
   "AMSOBJ"."APPEAL_LOCATION"

WHERE  
        "LPA_F2"."NAME"="AMSOBJ"."APPEAL_LOCATION"."ASSIGNED_FROM_USER_NAME" 
AND "LPA_T1"."NAME"="AMSOBJ"."APPEAL_LOCATION"."ASSIGNED_TO_USER_NAME" 



IN my Custom expression i'm returning something like:


string fieldName = base.DatabaseSpecificCreator.CreateFieldName(field, field.SourceColumnName, field.ObjectAlias, "");
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 18:58:40   

The object alias of the field has to be the same, so it has to be "A" as well, is that the case?

Frans Bouma | Lead developer LLBLGen Pro
Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 25-Sep-2006 14:55:05   

Yes it is the same in the code the problem is the part in the relation(from and where clause) get changed from FromUserName to LPA_F2...I want to know why LLBL is changing les alias names and is there a way to call the same function to do the same "translation" for my custom expression ??

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 25-Sep-2006 20:10:56   

Hi,

the best way to keep the aliases in sync is to reuse the fields of the objects you create in the first place. You've got access to ResultSet fields, Entity fields etc... Then you should either use explicit aliasing with all of your objects (by reusing custom fields or forcing the aliases), or avoid using aliases if you don't need it in you query(multiple accesses to the same table ).

Hope that helps

Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 26-Sep-2006 19:32:19   

No this does not help...sorry...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2006 08:36:11   

No this does not help...sorry...

Please elaborate more. What have you used from the previous suggestion and what went wrong?

Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 28-Sep-2006 14:24:55   

Please tell me where the aliases are translated and how I can use the function to force a translation on a custom expression.

thanks

Banane avatar
Banane
User
Posts: 67
Joined: 01-Sep-2004
# Posted on: 28-Sep-2006 14:40:10   

Here is my select



DataTable dt = new DataTable();

        IPredicateExpression filter = new PredicateExpression();

        //// Create the table we will be returning.
        ResultsetFields fields = new ResultsetFields(7);

        fields.DefineField(SecurityUsersFieldIndex.FirstName,0, "AssignedByUser", "FromUserName");
        fields.DefineField(AppealLocationFieldIndex.AssignedFromUnitCd ,1, "AssignedByUnit");
        fields.DefineField(SecurityUsersFieldIndex.LastName,2, "AssignedToUser", "ToUserName");
        fields.DefineField(AppealLocationFieldIndex.AssignedToUnitCd, 3, "AssignedToUnit");
        fields.DefineField(AppealLocationFieldIndex.FileActionCd, 4, "FileAction");
        fields.DefineField(AppealLocationFieldIndex.TransferredDt, 5, "TransferDate");
        fields.DefineField(AppealNoteFieldIndex.AppealNoteDesc, 6, "Notes");

        // concatenate the name fields
        IEntityField[] concatAssignedBy = new IEntityField[] {
EntityFieldFactory.Create(SecurityUsersFieldIndex.FirstName).SetObjectAlias(fields[0].ObjectAlias),
EntityFieldFactory.Create(SecurityUsersFieldIndex.LastName).SetObjectAlias(fields[0].ObjectAlias)};

fields[0].ExpressionToApply = AMS.BLL.Utilities.Queries.GetConcatFieldsExpression(concatAssignedBy, "{0} {1}");

        IEntityField[] concatAssignedTo = new IEntityField[] {
EntityFieldFactory.Create(SecurityUsersFieldIndex.FirstName).SetObjectAlias(fields[2].ObjectAlias),
EntityFieldFactory.Create(SecurityUsersFieldIndex.LastName).SetObjectAlias(fields[2].ObjectAlias)};

        fields[2].ExpressionToApply = AMS.BLL.Utilities.Queries.GetConcatFieldsExpression(concatAssignedTo, "{0} {1}");

        IRelationCollection relationsToUse = new RelationCollection();

        relationsToUse.Add(SecurityUsersEntity.Relations.AppealLocationEntityUsingAssignedToUserName, "ToUserName", "", JoinHint.None);
        relationsToUse.Add(AppealNoteEntity.Relations.AppealLocationEntityUsingAnAppealLocationId, JoinHint.Right);
                
        filter.Add(PredicateFactory.CompareValue(AMS.DAL.AppealLocationFieldIndex.AppealId, ComparisonOperator.Equal, iAppealId));

        ISortExpression sort = new SortExpression();
        sort.Add(SortClauseFactory.Create(AMS.DAL.AppealLocationFieldIndex.TransferredDt, SortOperator.Descending));
        
        TypedListDAO dao = new TypedListDAO();

        bool b = dao.GetMultiAsDataTable(fields, dt, 100, sort, filter, relationsToUse, true, null, null, 0, 0);

        return dt;


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 29-Sep-2006 13:20:26   

You specify NOWHERE the FromUserName relation addition to the relationcollection. So, not all code is posted.

Ok, enough time wasted. Please read the guidelines in the sticky thread here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7725

Please give us more info, and the code of your custom expression, as your code will call eventually FindRealAlias and it has to find the real alias. But unless we know which version and build of the runtimelibs we're talking about, how your expression code looks like, we can drag this on for ages but it won't lead to a solution.

Frans Bouma | Lead developer LLBLGen Pro