how can return a entity ?

Posts   
 
    
heyu52
User
Posts: 21
Joined: 27-Apr-2010
# Posted on: 07-May-2011 03:47:12   

my SQL select s.*,b.brandname from stock s left join brand b on s.brandcode=b.brandcode WHERE S.itemCode='001'

itemcode is the table stock PK,brandcode is the table brand pk, how can i fetch a stock entity ? i want to return a entity ,not a datatable

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-May-2011 06:26:17   

In this case Stock is the entity you want to fetch, and Brand is a related object you should attach to your main entity via a PrefetchPath. For example (from previous post I assume you are using Adapter and LLBLGen v3.1):

StockEntity stock = new StockEntity("001");
IPrefetchPath path = new PrefetchPath((int) EntityType.StockEntity);
path.Add(StockEntity.PrefetchPathBrand);

using (var adapter = new DataAccessAdapter())
{
     adapter.FetchEntity(stock, path);
}

// now your entity and the related brand are fetched, you can access them this way i.e
int stockQty = stock.Quantity;
string brandName = stock.Brand.BrandName;

This requires the two entities to be related, I assume they are, either via a DB relation or via a custom relation in LLBLGen designer.

David Elizondo | LLBLGen Support Team
heyu52
User
Posts: 21
Joined: 27-Apr-2010
# Posted on: 07-May-2011 10:48:13   

but the stock entity and the brand entity has not Related

heyu52
User
Posts: 21
Joined: 27-Apr-2010
# Posted on: 07-May-2011 10:51:51   

i add a brandname Attribute for stock,if no related ,Is there another way?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-May-2011 18:07:58   

If they are not related in database, you should relate them in the Desginer, creating a custom relationship. Otherwise the prefetchpath is not generated and can't be used.

David Elizondo | LLBLGen Support Team