Alias Problem

Posts   
 
    
ZaneZ
User
Posts: 31
Joined: 21-Dec-2004
# Posted on: 23-May-2006 19:49:16   

I'm not sure if this is a bug or not, but when I try to add a CustomFilter to a relation, the alias that I use in the CustomFilter, doesn't match the LLBLGenPro genearated alias, thus causing an error in SQL.

Here is an example of the relation that i'm adding:


  IEntityField2 cpField = EntityFieldFactory.Create(CustomPropertyFieldIndex.CustomPropertyID);
                //cpField.SetObjectAlias("cpv");
                bucket.Relations.Add(ContactEntity.Relations.CustomPropertyValueEntityUsingNSEntityKey, "cpv", JoinHint.Left).CustomFilter = 
                    new PredicateExpression(new FieldCompareValuePredicate(
                    cpField, null, ComparisonOperator.Equal, cp.CustomPropertyID, "cpv"));

note. cp.CustomPropertyID is an integer being declared outside the scope of the function.

Here is the Generated SQL for that statement:


LEFT JOIN [DEV].[dbo].[CustomPropertyValue] [LPA_c4]  
    ON  [DEV].[dbo].[Contact].[ContactID]=[LPA_c4].[NSEntityKey] 
    AND ( [cpv].[CustomPropertyID] = @CustomPropertyID2)) LEFT JOIN 

As you can see, the AND claus of the SQL query uses my Alias rather then the LLBLGenPro generated alias. Could this be a bug with 1.0.2005.1? Is there something that I need to add to make sure the alias gets converted to the LLBLGenPro alias? Is there a way to dynamically turn off the LLBLGenPro converted aliases?

I've tried many many combinations of FieldCompare functions, and all of them have the same result when creating the CustomFilter predicate expression.

ZaneZ
User
Posts: 31
Joined: 21-Dec-2004
# Posted on: 23-May-2006 20:16:31   

Ok, this seemed to work. I'm not why creating the entity field using the EntityFieldFactory within the function is any different then passing a referece to an entityfield and passing it into the function. But LLBLGen is now correctly creating its custom aliases in the SQL query.


bucket.Relations.Add(ContactEntity.Relations.CustomPropertyValueEntityUsingNSEntityKey, "cpv", JoinHint.Left).CustomFilter = 
                    new PredicateExpression(new FieldCompareValuePredicate( EntityFieldFactory.Create( CustomPropertyValueFieldIndex.CustomPropertyID), null, ComparisonOperator.Equal, cp.CustomPropertyID, "cpv"));