Object referense error when filtering

Posts   
 
    
Johan
User
Posts: 3
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 14:02:08   

Hi!

First a warning...I'm a fresh newbie with LLBLGen!

I run this routine to filter and sort a table. I get an "Object not set to an instance of an object" error. My code looks like this


private void LoadMemberOfCompanies(IEntity User)
        {
            var CompaniesSelected = new CompanyTypedList();
            
            // Filter expression
            IPredicateExpression filter = new PredicateExpression
              {
                  new FieldCompareSetPredicate(
                      User.Fields["UserId"], UserInCompanyFields.UserId, SetOperator.In, null)
              };

            // Sort expression
            ISortExpression sorter = new SortExpression { CompanyFields.Company | SortOperator.Ascending };
            
            // Get them all, sorted and with duplicates
            CompaniesSelected.Fill(0, sorter, true, filter);

            // Bind to list
            listUserCompaniesSelected.DataSource = CompaniesSelected;
            listUserCompaniesSelected.ValueMember = "CompanyId";
            listUserCompaniesSelected.DisplayMember = "Company";
        }

It works fine if I'm not having the filter when doing the Fill().

Any help would be very much welcomed!

Cheers, Johan Fredriksson SPESO

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 15:32:20   

Please try this:

             IPredicateExpression filter = new PredicateExpression
             {
                 new FieldCompareSetPredicate(
                     UserFields.UserId, UserInCompanyFields.UserId, SetOperator.In, null)
             };
Johan
User
Posts: 3
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 15:55:11   

Same reference error still.

What I have is a table "UserInCompany" containing "UserId" and "CompanyId" fields.

So what I want to do is to load companies that has its "CompanyId" in the "UserInCompany" table and where "UserId" = currently selected "UserId" from a combobox (int value).

Am I trying to do this the wrong way? I checked so all tables, names and so on is ok, data is in tables and they load without the filter (but then of course show all).

confused

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 16:09:00   

Then The filter should be like this:

             IPredicateExpression filter = new PredicateExpression
             {
                 new FieldCompareSetPredicate(
                     CompanyFieldsId, UserInCompanyFields.CompanyId, SetOperator.In, new PredicateExpression(UserInCompanyFields.UserId == someSelectedValue))
             };
Johan
User
Posts: 3
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 16:30:01   

And it works perfect! smile

Thank you very much for your help!

Cheers /Johan

PS. I'm really enjoying my first hands on experience with LLBLGen! Bit harsh to do it last minute for a program that needs to go live, but learning with pressure works to. stuck_out_tongue_winking_eye