Using EntityClasses as dump objects

Posts   
 
    
rasmus
User
Posts: 5
Joined: 12-Jan-2005
# Posted on: 13-Jan-2005 12:16:35   

Hi,

I sometimes need to use EntityClasses as dumb objects. However when I assign a property on a member object the property does not reflect this.

Here is an example of my problem:

This works:


PersonEntity person = new PersonEntity();
person.Name = "llbl";  
string test1 = person.Name;

test1 is "llbl"

This does not work:


PersonEntity person = new PersonEntity();
person.Car.Name = "ford" 
string test2 = person.Car.Nickname;  

test2 is empty

Regards,

Rasmus Oudal Edberg

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jan-2005 12:27:09   

person.Car.Name = "ford" string test2 = person.Car.Nickname;

why would Nickname all of a sudden have a value? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
rasmus
User
Posts: 5
Joined: 12-Jan-2005
# Posted on: 13-Jan-2005 13:17:35   

Sorry it should have been


person.Car.Name = "ford"
string test2 = person.Car.Name; 

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jan-2005 14:46:29   

Well, what's likely the case is that 'car' is fetched using lazy loading and because the parent entity, person, is not fetched, car will not be found in the db because the PK is not set in person. This means that you'll get a new entity for car, every time you access it.

To overcome this: PersonEntity person = new PersonEntity(); person.Car = new CarEntity(); person.Car.Name = "ford";

Frans Bouma | Lead developer LLBLGen Pro