FetchTypedList not returning records

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 24-Nov-2004 12:42:35   

I am using the FetchTypedList adapter method to return all rows from a user table as a DataTable... I am then going to use this as the source for my ReadOnly grid

Although I have generated the code of one SQL Server database, the connection string I am using is actually pointing to a different database with the same structure (I used the Generate Script option in SQL server to generate the script for the new database)

The code I am using is



mEntity = new UserEntity();

DataAccessAdapter myAdapter = new DataAccessAdapter("..ConnectionString..");
DataTable myDataTable = new DataTable();
myAdapter.FetchTypedList(mEntity.Fields,myDataTable,null);
System.Console.Writeline(myDataTable.Rows.Count.ToString());
return myDataTable;

The problem that I have is that although I am sure that the connection string is correct and that the database user table has 2 records in it, when i run this code no rows are returned.

Is there anything wrong with my code that could be causing this?

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 24-Nov-2004 13:08:54   

I have more information that may help (sorry Im new to this LLBL stuff)

I am trying to build a set of objects that hide the LLBL entities from my presentation layer, and at the moment I am working on a user entity that will become the users of my application... once I get this one right then I will work on the others.

This idea is that I create a class User that subsequently passes all requests on to the LLBL UserEntity class therefore I get the code


public class User
{
private UserEntity mEntity;

public User()
{
mEntity = new UserEntity();
}

public User(int id)
{
DataAccessAdapter myAdapter = new DataAccessAdapter("..ConnectionString..");
mEntity = new UserEntity(id);
myAdapter.FetchEntity(mEntity);
}

}


I then have a whole load of properties that relate to the individual fields


public int UserID
{
get{return mEntity.UserID;}
set{mEntity.UserID = value;}
}


... etc

however when I run the code



MyBusinesObject.User myUser = new MyBusinessObject.User(1);
Console.Writeline(myUser.UserID.ToString());


I get the error

"The entity is out of sync with the data in the database. Refetch the entity before using the in-memory instance"

I am obviously doing something utterly stupid but I cant see what... any ideas?

Thanks in advance

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-Nov-2004 14:00:37   

THe catalog name is in the entity persistence information. You have to specify catalog name overwriting options to map code onto another database. Please see in the documentation: "Using the generated code/Adapter/DataAccessAdapter functionality -> CatalogSpecific persistence info (SqlServer specific)"

Frans Bouma | Lead developer LLBLGen Pro
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 24-Nov-2004 14:37:38   

Thanks I am now using a different DataAccessAdapter overlaod and everything works fine

I shall now continue to build my generic admin windows forms and if I can gety that to work then LLBL will have saved me LOADS of time )