Access a dependent object with fields

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 04-Apr-2005 00:02:14   

Hi,

I'm accessing an entity's fields like so...


entity1.Fields["MemberName"].CurrentValue;

But when I try and access a dependent object like this I get a null reference.

Is there a way of accessing fields and dependent objects with a single accessor?

If not, how do I access a dependent entity if I have a string containing its name?

Cheers,

Ian.

Edit: I need to get to depending objects in a generic way too!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Apr-2005 09:34:34   

You mean, you want to access order.CustomerID (the FK field) and order.Customer (the related object) in a generic, unified way?

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 04-Apr-2005 10:41:55   

Yes, and order.OrderDetails ( the child objects ).

So idealy I could do something like this..


entity1.Fields["OrderDetails"].CurrentValue;
entity1.Fields["CustomerID"].CurrentValue;
entity1.Fields["Customer"].CurrentValue;

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Apr-2005 10:59:35   

Ian wrote:

Yes, and order.OrderDetails ( the child objects ).

So idealy I could do something like this..


entity1.Fields["OrderDetails"].CurrentValue;
entity1.Fields["CustomerID"].CurrentValue;
entity1.Fields["Customer"].CurrentValue;

Ah ok. That's not possible: you have entity fields (the fields which are forming the entity) and you have related entities, which are references, either through a collection or directly. As these are different concepts, they're not set by the same interface, because Order.Customer isn't a field, it's a related entity, and Customer.Orders is a set of related entities.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 04-Apr-2005 11:22:36   

Is it possible to access a related entity and related entities given a string which contains the name of the property on the object which references these things even if I can't access all of the different types of properties in a generic way?

As these are different concepts, they're not set by the same interface

They are ultimately all properties on a object though. I can still do..


entity1.Customer;
entity1.orderDetails;
entity1.CustomerID;

I suppose I could use reflection here but, of course, this will be slower.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Apr-2005 09:51:33   

Ian wrote:

Is it possible to access a related entity and related entities given a string which contains the name of the property on the object which references these things even if I can't access all of the different types of properties in a generic way?

No, that's not possible. Though if you could elaborate a bit about why you'd need this, I could perhaps suggest some actions which could make that possible.

Frans Bouma | Lead developer LLBLGen Pro
Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 05-Apr-2005 12:38:32   

Hi,

I had the same scenario. I need to access some dependent/depending entities from a generic business class, others clasess derived from this generic business class and I wanted to use a generic routine to handled entities with similar structure. My workaround was to declare MustOverride functions that I call from the generic business class; but I have to implement it in the derived clasess.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 05-Apr-2005 15:30:14   

Thanks for your replies.

I'm working on a UI Mapper which is a modification of Paul Wilson's UI Mapper. http://www.uimapper.net

An entity's fields need to be mapped onto UI elements. The code just iterates over the entity's fields copying the value back and forth between the corresponding UI element.

But my modification allows a user to modify an entity and one of its related entities in the same UI. The related entity can be mapped to a special UI element which then further maps the related entity's fields to standard UI elements. (So this is using nesting.)

So, as I hope you can see from my description, the property on the entity which references the related entity needs to be just another data field so that the UI mapping code can treat it like any other field.

I'm currently using reflection.

Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Apr-2005 11:06:28   

You'll always keep a distinction between the fields of an entity (the Fields object) and the objects which are related to an entity as there is no way the Fields object can offer you these references.

I'm not that familiar with Paul's uimapper, as in that I don't know if it can use a get/set method combination. If so, you could generate a GetPropertyValue and a SetPropertyValue method using an include template (see TemplateStudio's documentation for a tutorial on this), which accept a string and return an object / set an object by simply calling the property (this is generated code, so no reflection)

Frans Bouma | Lead developer LLBLGen Pro