DefaultView

Posts   
 
    
heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 13-Sep-2006 22:52:19   

Hi there, When I fill a entitycollection, will the defaultview be immediatly available? I ask this because I can't explain this:

        _permissionsCollection = new PermissionsCollection();
        _permissionsCollection.GetMulti(null);

// _permissionsCollection.Count is now 29

// but _permissionsCollection.DefaultView.Count is 0 !!

any ideas?! tanx!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Sep-2006 08:13:40   

The count should be the same.

What's the runtime library version that you are using (right click on the "SD.LLBLGen.Pro.ORMSupportClasses.NETxx.dll" file select Properties, then go to the version tab, and there you will find the "File Version" )?

heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 14-Sep-2006 17:29:16   

the version is: 2.0.0.60712

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 14-Sep-2006 17:54:56   

heerser wrote:

the version is: 2.0.0.60712

That's an oldie. simple_smile Could you try with the latest runtimes?

Frans Bouma | Lead developer LLBLGen Pro
heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 15-Sep-2006 21:20:57   

same result with this version: 2.0.0.60911

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 15-Sep-2006 22:10:27   

when do you retrieve the defaultview? before or after the getmulti?

Frans Bouma | Lead developer LLBLGen Pro
heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 15-Sep-2006 22:34:29   

after, this is the compleet code:

    static TblPermissionsCollection _tblPermissionsCollection;
    static object lockObject = new object();

    static Security()
    {
        _tblPermissionsCollection = new TblPermissionsCollection();
        _tblPermissionsCollection.GetMulti(null);
    }
    public static bool CheckAddItemPermission(long OperatorID, int AppID)
    {
        lock (lockObject)
        {
            IPredicateExpression filter = new PredicateExpression(TblPermissionsFields.IdOperator == OperatorID );
            filter.AddWithAnd(TblPermissionsFields.IdApp == AppID); 
            _tblPermissionsCollection.DefaultView.Filter = filter;
            return _tblPermissionsCollection.DefaultView.Count > 0;
        }
    }
heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 15-Sep-2006 23:14:22   

Nevermind the first post, _tblPermissionsCollection.DefaultView.Count is the same after the GetMulti flushed

but I still have a question, is there something wrong with this IPredicateExpression?:

IPredicateExpression filter = new PredicateExpression( TblPermissionsFields.IdOperator == 1 ); _tblPermissionsCollection.DefaultView.Filter = filter;

_tblPermissionsCollection.DefaultView.Count is now 0 although there is an entry in the collection:

IdLevel IdOperator IdApp 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 2 1 1 2 2 1 5 5 1 5 6 1 5 7 1 5 8 1 5 9 2 3 1 2 3 2 2 5 1 2 5 2 2 5 3 2 5 4 2 5 10 3 4 1 3 6 1 3 6 2 3 6 3 3 6 4

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Sep-2006 04:01:38   

Try something like this.

IPredicateExpression filter = 
new PredicateExpression( TblPermissionsFields.IdOperator == 1 );
EntityView permissionView = _tblPermissionsCollection.DefaultView;
permissionView.Filter = filter;

heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 16-Sep-2006 22:30:39   

hmmm that works indeed smile

manner of RTFM:

/// <summary> /// Gets the default view for this entitycollection. The returned value is a new instance every time this property is read. It's a new entity view without a /// filter or a sorter. /// </summary> /// <value>The default view.</value>

tanx!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 17-Sep-2006 11:35:07   

That's a bug in the docs, it returns the same entityview instance, everytime the property is read flushed . I'll fix that.


/// <summary>
/// Gets the default view for this entitycollection. The returned value is a new instance every time this property is read. It's a new entity view without a
/// filter or a sorter.
/// </summary>
/// <value>The default view.</value>
[Browsable( false ), XmlIgnore]
public EntityView<TEntity> DefaultView
{
    get 
    {
        if( _defaultView == null )
        {
            _defaultView = new EntityView<TEntity>( this );
        }
        return _defaultView;
    }
}

Frans Bouma | Lead developer LLBLGen Pro
heerser avatar
heerser
User
Posts: 36
Joined: 15-May-2005
# Posted on: 17-Sep-2006 21:25:13   

Hmmm thats why I couldn't explain some of its behaviour ;-)

there is propably a very simple explanation for all of this, and there is....

IPredicateExpression filter = new PredicateExpression(TblPermissionsFields.IdOperator == OperatorID);

TblPermissionsFields.IdOperator is an int and OperatorID is a long

after changing IdOperator to int, it works like a charm.

so we can all go to sleep now |-)

tanx for al the quick replies !!!