Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Doing CRUDy stuff with the Table service (part 2) - Adding entities & Listing entities

3/12/2011 10:45:26 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Adding entities

Now that you have your context class, you can start creating your product-management web page. To do this, you need to add a new ASP.NET web page called products.aspx.

At this stage, we won’t generate the grid listing all the Hawaiian shirts for sale; we’ll only write the code required to add shirts to the Products table. Therefore, you only need to add the markup for the bottom section of the products page.

The listing that follows contains the ASPX code that you should add to the products.aspx page.

Listing 2. Adding the shirt section of the products.aspx page

When the Add button is clicked in listing 2, the shirt entity will be added to the Products table.

Listing 3 contains the code for the Add button’s click event. This code should be added to the products.aspx code-behind.

Listing 3. Add the entity to the Products table

To add the new shirt details, which were entered on the web page, to the Products table, you need to extract all the information entered about the product (ID, name, and description) and create a new instance of the Product class called newShirt . Once you’ve created an instance of the shirt , you add the shirt entity to a tracking list held in the context object for the product list.

When you add the entity to the tracking list , you also specify the table that the entity should be added to. The product context object (shirtContext) maintains a list of all objects that you have changed as part of this operation. You can create, update, or delete objects from the product list, and you can add all these changes locally to the tracking list.

Eventually, when you wish to perform all the changes on the server side, you can invoke the SaveChanges method on the context object , which will apply all the tracked changes on the server side using ADO.NET Data Services via the REST API.

Was the Entity Added?

You should now be able to run the product-management web page and add new shirts to the product list. We haven’t yet implemented the grid to display the list of entities in the product list—we’ll do that in the next section. In the meantime you can always check that your entity exists by querying the development storage database using the following statement in SQL Management Studio:

SELECT * FROM TableRow

3. Listing entities

It’s now time to extend the products.aspx web page to display the list of shirts stored in the Products table. The following listing contains the code required for your grid. This code should be placed above the code in listing 2.

Listing 4. ASP.NET grid for displaying shirts

The grid in listing 4 will display the product ID, name, and description for each shirt in the Products table. The name and description columns will both be editable, but the product ID won’t be.

At this stage, you’ve defined the markup required to edit and delete the shirts in the table, but we won’t write the code-behind for these events just yet. The following listing contains the code-behind for the products.aspx page, which you’ll require to populate the new grid with the list of shirts.

Listing 5. Populating the list of shirts

As you can see, the code to bind the GridView to the list of shirts held in the Products table is pretty simple. On the first load of the web page , the BindGrid is called to populate the grid with the list of shirts retrieved from the Products table. method

To retrieve the list of shirts, you instantiate the product context object (shirtContext) and set the data source of the grid to the Product property of the context object.

By returning an IQueryable list of products from the context object, you can define a query using LINQ that will be executed on the server side when you enumerate the list of objects, which happens when the grid is data bound .

To keep this example simple, we won’t perform any server-side filtering at this stage. We’ll simply return a list of all shirts in the Products table as shown at .

Other -----------------
- Developing with the Table service
- Partitioning data across lots of servers : Partitioning the storage account & Partitioning tables
- Modifying an entity to work with the Table service
- How we’d normally represent entities outside of Azure
- A brief overview of the Table service
- BLOBs : Setting shared access permissions
- Enterprise Service Bus with BizTalk Server and Windows Azure : Distributed and Scalable ESB Architecture
- Enterprise Service Bus with BizTalk Server and Windows Azure : The ESB Toolkit
- Enterprise Service Bus with BizTalk Server and Windows Azure : Integration with BizTalk
- Copying BLOBs - Copying files via the StorageClient library
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server