Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clean way to reference 'current' entity?
Message
From
21/08/2008 01:37:24
 
 
To
20/08/2008 11:51:06
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:
01340683
Views:
13
>>>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
>
>You do not need to overwrite your existing EntityList. You can return a different DataSet or DataRow as you wish. It is all in how you do this in your business object method. If you want to just get a DataSet or DataRow then use this.GetDataSet() in the business method. You can reduce it to a row before passing it back if you want to. I have forms that retrieve two different sets of data from the business object based on the same business object and same underlying table. I am including my example to show you as it may be the easiest way to convey one way to do this.
>
>Here is an example where I need two different sets of data from the same business object. I am returning DataSets and binding them to two different grids.
>
>// In my form I have this:
>protected DisplayItems oItems;
>protected DataSet dsNews;
>protected DataSet dsEvents;
>
>// Get News Items
>this.dsNews = this.oItems.GetItemsDataSetByType(DisplayItemType.News, false, "News");
>if (this.dsNews.Tables[0].Rows.Count > 0)
>{
>	this.grdNews.DataSource = dsNews;
>	this.grdNews.DataBind();
>}
>else
>	this.lblNews.Visible = false;
>
>// Get Event Items
>this.dsEvents = this.oItems.GetItemsDataSetByType(DisplayItemType.Events, false, "Events");
>if (this.dsEvents.Tables[0].Rows.Count > 0)
>{
>	this.grdEvents.DataSource = dsEvents;
>	this.grdEvents.DataBind();
>}
>else
>	this.lblEvents.Visible = false;
>
>// In my business object I have this:
>public DataSet GetItemsDataSetByType(DisplayItemType itemType, bool isPrivate, string tableName)
>{
>	// 1-18-2008 Adding a check for expire date
>	DateTime rightNow = DateTime.Now;
>	return this.GetDataSet("SELECT * FROM DisplayItems WHERE ItemType = @Type AND MarkPrivate = @Private AND @RightNow > BeginDate AND @RightNow < ExpireDate ORDER BY DateOfItem DESC",
>	tableName,
>	this.CreateParameter("@Type", itemType),
>	this.CreateParameter("@Private", isPrivate),
>	this.CreateParameter("@RightNow", rightNow));
>}
>
>
>Now I wouldn't necessarily do my code the same as above today, but using it as an example.
>
>I hope that helps.
>Tim

Does help Tim, I'll give this a try.

Once again, thank you.

-Larry
Previous
Reply
Map
View

Click here to load this message in the networking platform