'Newbie' Question

Posts   
 
    
CliffH
User
Posts: 52
Joined: 03-May-2006
# Posted on: 16-May-2006 17:52:55   

LLBLGen us quite hard to get into, but probably worth the effort.

I need a filter expression to validate a login. Something like IPredicateExpression filter = new PredicateExpression(); filter.Add( AppUserFields.LoginId == userId); filter.Add( AppUserFields.Password == password);

then I instantiate a DataAccessAdaptor.

Question is: what do I do to fetch the data. adaptor methods don't seem to be clear (enough) on this. I'm not interested in related data at this point, nor can I rely on an primary key, nothing I do seems to work.

Any suggestions appreciated.

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 16-May-2006 18:06:18   

CliffH wrote:

LLBLGen us quite hard to get into, but probably worth the effort.

I need a filter expression to validate a login. Something like IPredicateExpression filter = new PredicateExpression(); filter.Add( AppUserFields.LoginId == userId); filter.Add( AppUserFields.Password == password);

then I instantiate a DataAccessAdaptor.

Question is: what do I do to fetch the data. adaptor methods don't seem to be clear (enough) on this. I'm not interested in related data at this point, nor can I rely on an primary key, nothing I do seems to work.

Any suggestions appreciated.

You're not using .Net 2.0 by any chance are you?

BOb

CliffH
User
Posts: 52
Joined: 03-May-2006
# Posted on: 16-May-2006 18:27:17   

No vs 2003 framework 1.1 and adapter.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-May-2006 18:35:21   

You want to check if that row is present? You could go for a scalar query to fetch the userid, or you can just fetch the user entity.

Adapter uses RelationPredicateBuckets, which combine a PredicateExpression and RelationCollection. So, to fetch the AppUser entity belonging to that loginid/password combi, you can do:


AppUserEntity user = null;
RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add( AppUserFields.LoginId == userId);
filter.PredicateExpression.Add( AppUserFields.Password == password);
DataAccessAdapter adapter = new DataAccessAdapter();
user = adapter.FetchNewEntity(new AppUserEntityFactory(), filter);

After this code, user is either the entity from the db, or a new empty entity if the combination wasn't found. So all you do now is: bool validLogin = (user.IsNew==false);

A scalar query is more efficient in this. In a scalar query you basicly do SELECT UserID from AppUser WHERE loginid = @loginid AND password = @password

The Adapter.GetScalar method accepts predicates and /or relationcollections so we can use a predicateexpression here.


IPredicateExpression filter = new PredicateExpression();
filter.Add( AppUserFields.LoginId == userId);
filter.Add( AppUserFields.Password == password);
DataAccessAdapter adapter = new DataAccessAdapter();
object userId = adapter.GetScalar(AppUserFields.UserId, null, AggregateFunction.None, filter);
bool validLogin = (userId is int);

This fetches the userid as in the sql query given above into an object. Fetching into an object is required as the GetScalar can also return null. A valid login is a login which returns a true value with this query.

Frans Bouma | Lead developer LLBLGen Pro
CliffH
User
Posts: 52
Joined: 03-May-2006
# Posted on: 17-May-2006 08:27:21   

Alas, tried both without success. The first example:-

AppUserEntity toReturn = null; RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( AppUserFields.LoginId == userId ); filter.PredicateExpression.Add( AppUserFields.Password == password ); DataAccessAdapter adapter = new DataAccessAdapter(); toReturn = adapter.FetchNewEntity(new AppUserEntityFactory(), filter); bool ValidLogin = (toReturn.IsNew == false );

will not compile. c:\MidOffice\BL\AccountManager.cs(42): Cannot implicitly convert type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntity2' to 'Yatra.DAL.EntityClasses.AppUserEntity'

The second example:-

IPredicateExpression filter = new PredicateExpression(); filter.Add( AppUserFields.LoginId == userId); filter.Add( AppUserFields.Password == password); DataAccessAdapter adapter = new DataAccessAdapter(); object AppUserId = adapter.GetScalar(AppUserFields.AppUser_ID, null, AggregateFunction.None, filter); bool validLogin = (AppUserId is Int32);

bombs when the GetScalar adapter method is called, with:-

An unhandled exception of type 'System.InvalidCastException' occurred in yatra.daldbspecific.dll Additional information: Specified cast is not valid.

This is too hard ... harder than it should be, never felt so unproductive with a new tool for ages.

Any thoughts.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-May-2006 09:22:37   

CliffH wrote:

Alas, tried both without success. The first example:-

AppUserEntity toReturn = null; RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( AppUserFields.LoginId == userId ); filter.PredicateExpression.Add( AppUserFields.Password == password ); DataAccessAdapter adapter = new DataAccessAdapter(); toReturn = adapter.FetchNewEntity(new AppUserEntityFactory(), filter); bool ValidLogin = (toReturn.IsNew == false );

will not compile. c:\MidOffice\BL\AccountManager.cs(42): Cannot implicitly convert type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntity2' to 'Yatra.DAL.EntityClasses.AppUserEntity'

Sorry, I just typed it in from my bare head, it slipped my mind that I had to cast: toReturn = adapter.FetchNewEntity(new AppUserEntityFactory(), filter);

should be: toReturn = (AppUserEntity)adapter.FetchNewEntity(new AppUserEntityFactory(), filter);

The second example:-

IPredicateExpression filter = new PredicateExpression(); filter.Add( AppUserFields.LoginId == userId); filter.Add( AppUserFields.Password == password); DataAccessAdapter adapter = new DataAccessAdapter(); object AppUserId = adapter.GetScalar(AppUserFields.AppUser_ID, null, AggregateFunction.None, filter); bool validLogin = (AppUserId is Int32);

bombs when the GetScalar adapter method is called, with:-

An unhandled exception of type 'System.InvalidCastException' occurred in yatra.daldbspecific.dll Additional information: Specified cast is not valid.

PLease post stacktraces when an exception occurs. As with the previous example, I didn't test the code I posted in that message, so I might have made a small typo here and there.

This is too hard ... harder than it should be, never felt so unproductive with a new tool for ages. Any thoughts.

What have you read from the documentation, the example projects, the how-do-I section? Did you check the reference manual to see what type adapter.FetchNewEntity() returns?

Frans Bouma | Lead developer LLBLGen Pro
CliffH
User
Posts: 52
Joined: 03-May-2006
# Posted on: 17-May-2006 10:59:16   

Ok, done the (AppUser) casting, so code is:=

AppUserEntity toReturn = null; RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( AppUserFields.LoginId == userId ); filter.PredicateExpression.Add( AppUserFields.Password == password ); DataAccessAdapter adapter = new DataAccessAdapter(); toReturn = (AppUserEntity)adapter.FetchNewEntity(new AppUserEntityFactory(), filter); //bool ValidLogin = (toReturn.IsNew == false ); adapter.CloseConnection();

But while the FetchNewEntity method instantiates a new AppUserEntityFactory, it still bombs with:-

An unhandled exception of type 'System.InvalidCastException' occurred in sd.llblgen.pro.ormsupportclasses.net11.dll

Additional information: Specified cast is not valid.

What are we missing here?. Desparately need to clear this "brick wall" to make some progress. Yes I should have spotted the casting in the docs, but nothing in the docs indicates the above is incorrect.

Stack trace below.

'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded. 'PL': Loaded 'c:\MidOffice\PL\bin\Debug\PL.exe', Symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded. 'PL.exe': Loaded 'c:\midoffice\pl\bin\debug\bl.dll', Symbols loaded. 'PL.exe': Loaded 'c:\midoffice\pl\bin\debug\yatra.dal.dll', Symbols loaded. 'PL.exe': Loaded 'c:\midoffice\pl\bin\debug\sd.llblgen.pro.ormsupportclasses.net11.dll', No symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded. 'PL.exe': Loaded 'c:\midoffice\pl\bin\debug\sd.llblgen.pro.ormsupportclasses.cf11.dll', No symbols loaded. 'PL.exe': Loaded 'c:\midoffice\pl\bin\debug\yatra.daldbspecific.dll', Symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll', No symbols loaded. 'PL.exe': Loaded 'c:\windows\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.dll', No symbols loaded. An unhandled exception of type 'System.InvalidCastException' occurred in sd.llblgen.pro.ormsupportclasses.net11.dll

Additional information: Specified cast is not valid.

The program '[2456] PL.exe' has exited with code 0 (0x0).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-May-2006 11:32:48   

That's not a stacktrace, Cliff, the stacktrace is in the exception dialog you get, the list of at ... lines.

Did you reference the .NET11 ORM support classes or the .NET10 support classes by any chance? This is an error made sometimes, and which can lead to weird errors due to C# compiler changes made in .NET 1.1. The thing is: your code is OK and should work ok.

edit:


[Test]
public void FetchEmployeeTest()
{
    EmployeeEntity e = null;
    RelationPredicateBucket filter = new RelationPredicateBucket();
    filter.PredicateExpression.Add(EmployeeFields.FirstName == "Robert");
    filter.PredicateExpression.Add(EmployeeFields.LastName=="King");
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        e = (EmployeeEntity)adapter.FetchNewEntity(new EmployeeEntityFactory(), filter);
    }

    Assert.IsFalse(e.IsNew);
}

Frans Bouma | Lead developer LLBLGen Pro
CliffH
User
Posts: 52
Joined: 03-May-2006
# Posted on: 17-May-2006 11:54:51   

OK, cheers for this ... seems I had a reference to a CF orm support class in one of my assemblies.

Yes it works fine. Thanks indeed for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-May-2006 12:14:36   

Glad that's solved, Cliff simple_smile . And sorry for the inconvenience you have had with the framework. It has a learning curve, we are aware of that, just try to take one step at a time. wink . If you have more questions, just step forward and ask them.

Frans Bouma | Lead developer LLBLGen Pro