Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clean way to reference 'current' entity?
Message
From
19/08/2008 19:47:54
 
 
To
19/08/2008 16:49:45
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01339837
Message ID:
01340251
Views:
10
>>
>>Hi Tim,
>>okay sorry I goofed in trying to simplify my question, wasn't a good example. It's the child entities that seem to cause this problem.
>>
>>Instead, add a button to CustomerOrdersForm called btnShowOrderDetailLine. Have it call OrderDetail.ShowOrderDetailLine. In OrderDetail.Partial add public void ShowOrderDetailLine() {console.writeline(" ->order line ProductID is: " + this.Entity.ProductID);}
>>
>>On an order with multiple detail lines, OrderDetail.Entity is always the first entity, regardless of which is selected. So if I have the second line selected, I'd really be after this.EntityList[1].ProductID. Course they could be sorted so I have to be careful with the index.
>>
>>So the question is how can I call that with the selected entity (order detail line) instead? I'm thinking there is no currentindex type value in the entity for those child records.
>>
>>To answer your other questions: I'm justing using the console.writeline as a first step to getting the reference correct from within the bo. The actual code that I'd be doing (using these details) is to generate records elsewhere using values from the selected child record. It's in the BO since it's that business objects responsibility to create the records, not the user from the user interface.
>>
>>thanks,
>>-Larry
>
>Ok, I think I am getting closer to your question; see if I got this right? You have a parent record showing with it's associated child records and you want to select a specific child record and then retrieve that record for some other processing?
>
>If this is the case, then a method in the child biz obj that retreives that record would be something like this if the primary key is an int?
>oOrderDetail.GetOrderDetail(int, detailPK)
>
>The question then is how do you obtain that primary key of the selected child record; right?
>
>You need to retrieve this primary key from the interface where it is selected? In the sample app the detail records are in a grid. I have not tried this specifically but there is a GetCurrentRowPK() method on the mmDataGridView control if you are using one. There is also a GetCurrentRow() method on the DataGridView and I did try this.
>
>I tried this in the sample app for MM.
>1. I added a mmButton above the OrderDetail buttons on the Detail page of the customer orders form.
>2. I added a click event for the button and I put this. It works by giving me back the productID.
>
>
>
>private void btnTest_Click(object sender, EventArgs e)
>{
>	DataRowView row = this.grdOrderDetail.GetCurrentRow();
>	int pkVal = (int)row["ProductID"];
>	MessageBox.Show("PK is: " + pkVal.ToString());
>
>         //This could then be passed into your child business object method.
>         oOrderDetail.ShowOrderDetailLine(pkVal);
>}
>
>
>Hope that helps
>Tim

Hi TIm,

the question is then within that oOrderDetail, how to access the rest of the selected entity. It now 'knows' the pkVal as passed in the parameter, while in that oOrderDetail.ShowOrderDetailLine do I still have to loop through the entitylist until I find the one with that primary key.

So in your example above, move the MessageBox line to the oOrderDetail.ShowOrderDetailLine routine and add + " and qty is: " + ??? with the qty value for that selected entity.

If the related child list is long then looping through each entity to find the selected one is a performance hit, I thought there might be a cleaner approach.

-Larry
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform