Adding field from a related entity (not immediately adjacent)

Posts   
 
    
itPhoenix
User
Posts: 11
Joined: 03-May-2007
# Posted on: 17-Dec-2007 18:07:22   

Hello,

First of all, great product. I have never used an O/R Mapper or created a Windows Forms application before, but LLBLGen has made data access and persistance a breeze (not sure I could go back to using stored procedures, except where absolutely necessary). The documentation is excellent once you get the basics down and I find most of my questions end up being .net or forms related.

Not sure if this is possible or not, so I need to post the question here. Using v2.5, adapter, Windows Forms, .net2.0, vs2005...

Simplified Schema: Physician Entity 'Name' 'PhysicianId' (PK)

MalPractice Insurance Carrier Entity 'Name' 'CarrierId (PK)'

Physician Insurance Entity 'PhysicianId' 'CarrierId' 'StartDate' 'Termdate' 'Amount' 'AddressId" etc.

Address Entity 'AddressId' 'Zip' 'Street'

I have an entity collection that is bound to a datagridview. I use the grid for editing, where possible, or if complex editing is required, a context menu brings up a dialog box to edit the row. This has worked great for me so far... very easy. However, I have run into a problem where I cannot get one of the columns I need.

For instance, I have a collection of Physicians. Each physician has a M:N relation to Malpractice Insurance Carriers. I have a physician form where a datagridview is bound to the intermediate entity 'PhysicianInsurance'. If I want the Malpractice Insurance Carrier 'Name' to show up in the datagridview, I just use the 'Fields on related Fields' mapping that I created in the designer (and pull the related fields in through a static BLL function). This is not editable, but I use an edit dialog box for this (I have no problem with this, I can put a search function in the dialog and make everything very user friendly). So far so good.

However, I have one point in my schema where the related entity I want to map(fields on related fields) is not directly adjacent to my 'intermediate' entity (e.g. it is not a foreign key field). In the example above this could be the address entity. If I wanted to show the 'ZipCode' in my datagridview, how would I do that? Is it possible? The desiger doesn't seem to allow the mapping, and the datagridview doesn't allow referencing a column in a relatedentity.

I am not going to use master and detail datagridviews, so this is not an option. Does anyone have an ideas?

Thanks!

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 17-Dec-2007 18:41:46   

Hi,

Would it be possible for you to write a custom property for the entity which is bound to the gridview? You could create your own kind of "fields on related fields".

Cheers, Gab

itPhoenix
User
Posts: 11
Joined: 03-May-2007
# Posted on: 17-Dec-2007 18:46:56   

gabrielk wrote:

Hi,

Would it be possible for you to write a custom property for the entity which is bound to the gridview? You could create your own kind of "fields on related fields".

I'm not sure. Is there a way in the designer to make a custom property 'AddressZip' on the Physician Insurance Entity and have it point to 'PhysicianInsurance.Address.Zip'.

If so, that is the solution I am looking for. I haven't ever tried to use custom properties. I'll take a look...

itPhoenix
User
Posts: 11
Joined: 03-May-2007
# Posted on: 17-Dec-2007 18:53:21   

Actually, it appears that Custom Properties can only be strings and their value is set a design time...

Perhaps I need a custom relation to bring in the ability to create the field mapped on related fields?

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 17-Dec-2007 18:55:45   

Hi,

You could just change the generated code in a custom code area:


        // __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode

        // Custom code goes here
public string AddressZip
{
get
{
return PhyscianInsurcane.Address.Zip;
}
}

        // __LLBLGENPRO_USER_CODE_REGION_END

This way you can extend the entity with what ever property you want. The above assumes that Address is a single entity. Otherwise you could use Address[0] but you would need to verify the collection actually contains an entity.

cheers, Gab

itPhoenix
User
Posts: 11
Joined: 03-May-2007
# Posted on: 17-Dec-2007 19:17:01   

Thanks gabrielk. That's exactly what I needed. sunglasses