Not getting any values back

Posts   
 
    
daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 24-Jul-2007 16:57:51   

Hi

I am using v2.0.0 in adapter mode with SQL 2005.

When I try to bring back an entity by the Primary Key value, I am getting nothing but null values - even though the item does exist in the database.

AdminUserEntity oUser = new AdminUserEntity(1); DataAccessAdapter oAdapter = new DataAccessAdapter(); oAdapter.FetchEntity(oUser);

Is this the correct method?

What I was actually trying to do is see if a user existed based on the given username and password, I tried this:

AdminUserEntity oUser = new AdminUserEntity(); oUser.Email = txtUserName.Text; oUser.Password = txtPassword.Text;

DataAccessAdapter oAdapter = new DataAccessAdapter(); oAdapter.FetchEntity(oUser);

But this didn't work either.

Any help would be most appreciated.

Many thanks

Darren

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 24-Jul-2007 17:11:18   

Hi,

when you fetch an entity using this code:


AdminUserEntity oUser = new AdminUserEntity();
oUser.Email = txtUserName.Text;
oUser.Password = txtPassword.Text;

DataAccessAdapter oAdapter = new DataAccessAdapter();
oAdapter.FetchEntity(oUser);


You will fetch an empty entity because you define no PK(email and password are just fields).

You have to create a filter to get the user with that predicate.


DataAccessAdapter adapter = new DataAccessAdapter();
AdminUserEntity oUser = new AdminUserEntity();
IPredicateExpression ipe = ((AdminUserFields.Email == txtUserName.Text) & (AdminUserFields.Password == txtPassword.Text)) ;
myAdapter.FetchEntityUsingUniqueConstraint(oUser,ipe);


daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 24-Jul-2007 18:02:52   

Thanks JBB - I will give it a try now. I knew I was getting something wrong with the key... I'm sure I'll get that working fine now simple_smile

daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 24-Jul-2007 18:33:20   

JBB - I've just got one slight issue - I am getting an error to say I'm missing a namespace as it doesn't recoginise IPredicateExpression.

I've tried adding references to everything:

using RedStarEnergy.DAL;
using RedStarEnergy.DAL.DatabaseSpecific;
using RedStarEnergy.DAL.EntityClasses;
using RedStarEnergy.DAL.FactoryClasses;
using RedStarEnergy.DAL.HelperClasses;
using RedStarEnergy.DAL.RelationClasses;

But this hasn't solved the problem.

Many many thanks for your help

Darre

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Jul-2007 18:43:04   

using SD.LLBLGen.Pro.ORMSupportClasses; wink (IPredicateExpression is defined in the runtime libs)

Frans Bouma | Lead developer LLBLGen Pro
daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 24-Jul-2007 22:53:10   

Brilliant - I will give it a try. Thanks Otis.

Do I need to be including any other runtimes?

Darren

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 11:55:13   

Do I need to be including any other runtimes?

Depends on which classes and namespaces you use in code. But if you are using VS 2005, and you have the class name written correctly you can write click it and select "Resolve", which will automatically add the corresponding using statement.