Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clean way to reference 'current' entity?
Message
From
20/08/2008 11:24:10
 
 
To
20/08/2008 09:02:53
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:
01340390
Views:
11
>You can simply just make another call to retrieve that record.
>
>
>public OrderDetailEntity ShowOrderDetailLine(int detailPK)
>{
>     OrderDetailEntity orderDetailEntity;
>     this.GetEntity("SELECT * FROM OrderDetail WHERE ProductID = @ProductID",
>          this.CreateParameter("@ProductID", detailPK));
>
>     // to display locally which I don't recommend, I think you should pass it back to the UI to display it regardless of how
>     // you could just refer to the this.Entity.fieldNames here
>
>     // then pass back the entity
>     return orderDetailEntity;
>}
>
>
>In the button click above I would display the entity once it is returned back
>I had this in there
>oOrderDetail.ShowOrderDetailLine(pkVal);
>
>Just add this:
>Debug.WriteLine("ProductID is: " + oOrderDetail.Entity.ProductID.ToString() + "Product Name is: " + oOrderDetail.Entity.Name etc...);
>
>
>
>You also could return just a DataRow if you wanted or a number of other ways. The answer I guess I am giving you is to collect the PK of the record and then pass it to the business object to just re-select it from the database and pass it back in some form for you to display at the UI level.
>
>I hope that helps
>Tim

Hi Tim,
ah but here's where the problem is, when I re-select it from the database in the manner you've suggested (assuming I've got it correct, please see below), when I get back to my form it is only displaying 1 order detail now, I have to reselect again. So I've just done two more queries even though I already had the data.

Here's how I implemented your suggestion:
In OrderDetail.Partial.cs
     public void ShowProduct(int orderPK, int productID)
      {
         OrderDetailEntity ode;
         ode = GetEntity("OrderDetailsSelectByPK",
            this.CreateParameter("@OrderID", orderPK),this.CreateParameter("@ProductID", productID));

         Console.WriteLine("in orderdetail.partial: OrderID is " + ode.OrderID.ToString() + " ProductID is: " + ode.ProductID.ToString() + "  qty is: " + ode.Quantity);
      }
I guess what you're telling me is there is no cleaner approach that what I've been doing, so in general the approach would be:
1) call the object.routine passing the primary key
2) in the object.routine loop through the entitylist looking for that primary key, and keep track of the index
3) reference the desired entitylist[indexfound]

Looping through entitylist works better then doing a re-select since that resets the calling form child list and in theory should be faster.

Sound correct?

thanks for your help and patience,
-Larry
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform