expression question

Posts   
 
    
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 22-Sep-2006 20:27:58   

how do I write filter for this

where U.UserId = Q.CreatedByUserId ?

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 22-Sep-2006 20:53:21   

found it

filter.AddWithOr(PredicateFactory.CompareExpression(QueryUserSettingFieldIndex.UserId, ComparisonOperator.Equal, New Expression(QueryFields.CreatedByUserId)))

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 22-Sep-2006 21:22:09   

ok after I figured how to do this I went and changed some of my other queires without changing factory from CompareValue to CompareExpression and it did not complain on this step

bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareExpression(QueryUserSettingFieldIndex.UserId, ComparisonOperator.NotEqual, New Expression(QueryShareToUserFields.ToUserId)))

but when trying to fetch I got "Object must implement IConvertible" error.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 23-Sep-2006 03:09:40   

Sorry I'm a little confused what is QueryShareToUserFields? Do you mean to use Expression? If you are just comparing fields then you can use bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareValue(QueryUserSettingFields.UserId, ComparisonOperator.NotEqual, QueryShareToUserFields.ToUserId)).

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 24-Sep-2006 00:57:17   

I had it initally like that but it did not work.

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 24-Sep-2006 01:10:09   

exp2000 wrote:

how do I write filter for this

where U.UserId = Q.CreatedByUserId ?

How are the entities "U" and "Q" related? If they are a one-to-many relationship for example, you would use relations instead of a predicate like this. Can you explain the relationship?

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 29-Sep-2006 23:32:39   

Sorry for delay,

Q= Query table that holds header information about the query U = QueryUserSetting that holds user settings, like title, description, expiration date etc.

so they are in 1:m relation, Q being on the 1 side. Approach that I used above works fine, but if there is a better way I would like to know.

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 29-Sep-2006 23:35:22   

Here is a full method

      Dim adapter As New DataAccessAdapter

            Try
                Dim fields As New ResultsetFields(6)
                SetBaseResultSetFields(fields)

                Dim bucket As New RelationPredicateBucket

                'create joins
                bucket.Relations.Add(QueryEntity.Relations.QueryShareToUserEntityUsingQueryId, "", "", JoinHint.Inner)
                bucket.Relations.Add(QueryEntity.Relations.QueryUserSettingEntityUsingQueryId, "", "", JoinHint.Inner)
                bucket.Relations.Add(QueryEntity.Relations.QueryHiddenFromUserEntityUsingQueryId, "", "", JoinHint.Left)

                'now create WHERE clause 
                Dim filter As New PredicateExpression
                bucket.PredicateExpression.Add(PredicateFactory.CompareValue(QueryShareToUserFieldIndex.ToUserId, ComparisonOperator.Equal, sharedToUserId))
                bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareValue(QueryFieldIndex.TabModuleId, ComparisonOperator.Equal, tabModuleId))
                bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareRange(QueryFieldIndex.QueryStatusCode, New String() {QueryStatus.SharedAsPeerToPeer, QueryStatus.SharedAsReference}))
                bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareExpression(QueryUserSettingFieldIndex.UserId, ComparisonOperator.NotEqual, New Expression(QueryShareToUserFields.ToUserId)))
                bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareNull(QueryHiddenFromUserFieldIndex.HiddenFromUserId))

                sorter.Insert(0, SortClauseFactory.Create(QueryFieldIndex.QueryStatusCode, SortOperator.Ascending))

                adapter.FetchTypedList(fields, tbl, bucket, 0, sorter, False, Nothing, 0, 0)
            Finally
                adapter.Dispose()
            End Try

            Return tbl
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 30-Sep-2006 02:55:54   

What are you wanting the typed list to be?

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 30-Sep-2006 04:05:47   

I am not sure I understand your question. I am pulling fields from several tables into a dynamic list and returning it as a datatable

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 30-Sep-2006 23:54:47   

exp2000 wrote:

Sorry for delay,

Q= Query table that holds header information about the query U = QueryUserSetting that holds user settings, like title, description, expiration date etc.

so they are in 1:m relation, Q being on the 1 side. Approach that I used above works fine, but if there is a better way I would like to know.

You can construct a query with the kind of sql syntax you're attempting, but if they are entities in a one-to-many relationship, then you're missing the power of LLBLGen. Here's an example of getting the "UserRoles" associated with a "User" in the AdventureWorks database:

    UserEntity user = new UserEntity(123);
    UserRoleCollection userRoles = user.UserRoleUserIdXuserId;