Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Instantiating and using two instances of the same BO
Message
From
16/07/2009 16:12:55
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
16/07/2009 13:56:00
Tegron Tegron
Platinum Technologies
Ohio, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01412544
Message ID:
01412841
Views:
41
>So what you are saying is that I could write another method that returned an entity list that contained different data than the first? This is basically what Linda's approach was accomplishing by using the FillDataSet for the second table?
>
>So could I have used Linda's method verbatim or would I have used something similiar to shaped entities from the developer's guide?

You could use Linda's suggestion to return the data in different data tables. Since this is Web and after the page finishes loading all the references to the business object go away and there isn't anything left anyway. I seem to remember you said these were grids, is that right? Here is what I have done in the past in my project.

I have a table that holds display information some of which is news and some of which are events. I wanted to display the news and events in two different grids on my page to differentiate the two types. Both come from the same business object. Since when you call a business object to retrieve data, it will retrieve data as an EntityList (a collection of entity objects) and underlying ADO objects such as a DataSet. In my case and because it was web I just retreived my data as a DataSet. Here is what I did.
// Business Ojbect reference
protected DisplayItems oItems;
protected DataSet dsNews;
proteced DataSet dsEvents;

protected void Page_Load(object sender, EventArgs e)
{
     this.oItems = (DisplayItems)RegisterBizObj(new DisplayItems());

     // Get News Items - The last parameter is the table name I want the data in.
     this.dsNews = this.oItems.GetItemsDataSetByType(DisplayItemType.News, false, "News");
     if (this.dsNews.Tables[0].Rows.Count > 0)
     {
          this.grdNews.DataSource = dsNews
          this.grdNews.DataBind();
     }
     // Get the 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();
     }
}

// In my business Object the method looks like 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));
}
Again in my case the data was display only; not going to be edited and it wasn't going to still be on the business object later anyway. If you need to save this data to do something with later you can save it to the session after you retrieve it as well. Something like this.
// After retrieving the DataSets
Session["dsNews"] = this.dsNews;

// Later, on a postback you can get this data back from the session and make it current on the business object again.
this.dsNews = (DataSet)Session["dsNews"]
this.oItems.SetCurrentDataSet(this.dsNews);
I hope this helps some.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform