More How-To's?

Posts   
 
    
Posts: 3
Joined: 04-Nov-2005
# Posted on: 04-Nov-2005 18:05:49   

looking for either some guidance or some more how-to's, specifically in regards to asp.net.

the guidance piece might direct whether or not i need the how-to's smile . excuse my ignorance at this point as i'm new to the ORM world (but enjoying it thouroughly to-date).

our data model has several entites that are two-part; the first is common in that a Person table contains common people info (name, etc.), the second part is the more specific data -- much like the typing of the data -- so, Customer, Employee, Manager, etc.

any entity requires both parts. you need fields from Person and Customer to get the customer's name.

so i want to bind a dropdown to my list of customers, for which i have filtered and used a prefetch path to get the Person objects...but now i don't really have a tap into the Person.Name field to bind to.

my feeling is that i'm either: a) missing something obvious b) going about things the wrong way, or c) needing to talk to the DBA about a model change

should i implement views? is there a way to 'push' a field up from Person to Customer through the framework/generated code?

short version: i have a list of Customers with a prefetched Person object in each; how do i bind, in a meaningful way, to the Customer.Person.Name property?

cheers, jc

wojt
User
Posts: 20
Joined: 27-Oct-2005
# Posted on: 05-Nov-2005 03:07:48   

I was just searching the forums looking for an answer to the same question, with no luck.

However, if you only need a limited number of fields, you can define a property within the Customer entity class to return a field from the Person entity.

This assumes you are using relationships so that the following code works:

CustomerEntity cust = new CustomerEntity(idCustomer);
string name = cust.Person.Name;

If it does, just add a property to CustomerEntity:

public string CustomerName
{
   get { return Person.Name; }
   set { Person.Name = value; }
}

Then bind to that property.

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 05-Nov-2005 04:59:16   

This thread addresses your issue and suggests work-arounds:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3361

wojt
User
Posts: 20
Joined: 27-Oct-2005
# Posted on: 05-Nov-2005 08:59:44   

Thanks, that's a nice alternative to hand-coding properties :-)

Posts: 3
Joined: 04-Nov-2005
# Posted on: 05-Nov-2005 17:52:48   

sweet. thanks, guys. this worked great and i'll explore it in a little more detail.

cheers, jc

Posts: 3
Joined: 04-Nov-2005
# Posted on: 05-Nov-2005 18:53:58   

if anyone else trips along this looking for the specifics, here's what i've found to be the solution:

1) Problem is this: you want to bind to a list of entities but use a property from a related table as the display. For example, you have a list of Customers, but the contact name is stored in the Person table.

2) In the Designer, right-click on the entity to pull up the editor (or hit CTRL+e). Navigate to the tab labeled 'Fields on Related Fields'.

3) Add your desired fields from any of the related entities. Save changes, export your project.

4) In your code, you'll need to do a few things to get at the data. In my case, I had a filter that I needed to apply to the list of Customers. We also need to prefetch the related entities so that the data is present when the framework goes looking for the value. The code looks pretty close to this (we use Adapter):


            // our data adapter
            DataAccessAdapter adapter = new DataAccessAdapter();

            // setup our filter to limit results on the type of customers
            IPredicateExpression filter = new PredicateExpression();
            filter.Add(CustomerFields.ClassificationId == 171);

            // create a prefetch path to allow the related person objects to be
            // made available
            IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CustomerEntity);
            prefetchPath.Add(CustomerEntity.PrefetchPathPerson);

            // create the collection and fetch the data
            EntityCollection customers = new EntityCollection(new CustomerEntityFactory());
            adapter.FetchEntityCollection(customers, new RelationPredicateBucket(filter), prefetchPath);

            // bind the data to the listbox
            listboxCustomers.DataSource = customers;
            listboxCustomers.DataTextField = "FullName";
            listboxCustomers.DataValueField = "AthleteID";
            listboxCustomers.DataBind();

that's it.

i actually was prefetching the person entities before, but then dropped it after i created the field mappings, thinking that, perhaps, the data from Person would be propagated up to Customer without having to retrieve Person. this isn't the case, and i added the prefetch back to get it working.

all is good...hope this helps someone else.

cheers, jc

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 07-Nov-2005 20:26:50   

I believe in version 1.0.2005.1 you can also just right click you Customer entity in the designer and choose "Make Sub-type of" and choose Person. This works as long as you have a one-to-one relation between Person and Customer.

wojt
User
Posts: 20
Joined: 27-Oct-2005
# Posted on: 08-Nov-2005 00:59:42   

tprohas wrote:

I believe in version 1.0.2005.1 you can also just right click you Customer entity in the designer and choose "Make Sub-type of" and choose Person. This works as long as you have a one-to-one relation between Person and Customer.

Thanks for the thought :-), but what we were having trouble with was accessing fields on related entities for databinding (i.e. the relationships were already established).