Create a movie data maintenance screen

Assignment Help Computer Engineering
Reference no: EM132991031

ITAP3011 Developing Windows Applications

Lab Tutorial

Object Persistence & Windows Forms Application Development using Entity Framework

The goal of this tutorial is to train you on how to work with ORM and carry out Object Persistence using the Microsoft Entity Framework when building a Windows Application. This tutorial assumes that you are familiar with the basics of EF through earlier tutorial and have practiced EDM creation and retrieving data using LINQ and Lambda. This tutorial and builds on the persistence operations which would help you to modify, add and delete records through working at Entity level.

The Microsoft Entity Framework is an Object Relational Mapping (O/RM) tool that enables you to generate a data access layer from a database automatically. The Entity Framework enables you to avoid the tedious work of building your data access classes by hand.

We shall continue working with the Dafesty database to illustrate the Entity Framework.

EDM Creation:

Create an Entity Data Model consisting of Customer and Country Entities to arrive at the following Model.

Note:
a. The following are the naming and choices that we have made:

i. Model Name: DafestyModel
ii. Context: DafestyEntities
iii. Include Foreign Key field is unchecked - so that country code does not appear as an attribute to the Customers entity.
b. Further Modelling: As a proof of concept to mapping variations, the MemberCategory column generated as an attribute has been renamed to MemberRating with appropriate mapping.
Driver Form:

Create a form as below to test the various operations.

Retrieving a single customer

Using the EDM, we would retrieve a single customer with id 1818 and display his Customer Name and Member Category in the Label.

private void QueryButton_Click(object sender, EventArgs e)
{
DafestyEntities ctx = new DafestyEntities();
Customer c = ctx.Customers.Where(x => x.CustomerID == "1818").First(); label1.Text = c.CustomerName + " " + c.MemberRating;
}

Note:
• We use MemberRating for the field when working with the object (not the column name MemberCategory).
• The .First method throws exception if there are no retrievals. If you want to avoid exception and assign null to c, then you would use .FirstOrDefault method.

Updating customer data

We would now modify the member category of customer 1818 from A to B. Note:
• To modify an existing customer, you should first retrieve the customer data from the database,
make the desired changes to the customer object and persist back to the database.
• Often, beginners make the mistake of trying to re-create a customer, which is wrong as you may be trying to create a duplicate row for the same customer and a exception would result. Hence first retrieve the object and then persist it.

private void QueryButton_Click(object sender, EventArgs e)
{
DafestyEntities ctx = new DafestyEntities();
Customer c = ctx.Customers.Where(x => x.CustomerID == "1818").First();

ctx.SaveChanges()
;
}

• The save changes method performs the necessary updates of all changes that has been done on the data held by the EDM context.
• This could include several changes to several entities and entity collections.
• Changes can be inserts, deletes, modification of values or even object association changes.
• Upon performing the updates review the database to ensure that the new value of MemberCategory (i.e., Customer 1818 is now B).

Creating a new customer
We would now create a new customer with id 1007 with CustomerName Venkat and MemberCategory as B.
This would eventually mean that a customer record gets inserted when the persistence operation is carried out.

private void QueryButton_Click(object sender, EventArgs e) {
DafestyEntities ctx = new DafestyEntities();

Customer c = new Customer(); c.CustomerID = "1007";
c.CustomerName = "Venkat"; c.MemberRating = "B";
ctx.Customers.Add(c);

ctx.SaveChanges();
} Note:
• Since the customer is a new customer, create a new object.
• Set all values and importantly the Customer ID, which should be assigned a value that no other current customer uses (else a primary key violation would occur).

• Add the customer object to the Customers collection of the context. Creation of new Customer object does not link it to the context automatically.
• The SaveChanges would determine that this is a new object added to the Customer Collection and hence would issue an Insert command to the database.

Deleting an existing customer
We would now demonstrate how to delete an existing customer. i.e, Customer with id 1007.

private void QueryButton_Click(object sender, EventArgs e)
{
DafestyEntities ctx = new DafestyEntities();

Customer c = ctx.Customers.Where(x => x.CustomerID == "1007").First(); ctx.Customers.Remove(c);

ctx.SaveChanges();
}


Note:
• Since the customer is existing customer, we would retrieve the customer object and delete.
• The operation requires to remove the object from the collection and save.
• The SaveChanges would issue the necessary delete statement to the database.
• It is important that you should delete a Customer who has no other related records in other tables.
Otherwise a foreign key violation may happen due to referential integrity check at the database.

EXERCISES

1. Create an EDM that would consist of Movie entity and Producer Entity.

2. Make sure your entity is called Movie and not Movy!

3. In the object model, MovieType should be called Genre and RentalPrice as RentalCost. Make the appropriate changes in one instance from the designer and in other instance in the XML code that defines the EDM.

4. Perform the following CRUD operations
a. Retrieve the movie with code 5 (Nemesis)
b. Update the rental cost of this movie to $1.80
c. Create a new Movie with id 400, name of the movie is Sully, genere is Drama, Producer is Warner Brothers, rental price is $2.50, Rating is U, number of copies (total stock) is 4.
d. Modify the Producer of Demolition Man (code 4) from Universal to Pixar. Alter the association from Movie object (1-side).
e. Modify the Producer of Die Hard 2 (code 11) from Pixar to Warner. Alter the association from the Producer side (n-side).
f. Delete the movie with code 400.

5. Create a Movie Data Maintenance Screen as below. Provide Navigation Buttons, and buttons for various CRUD operation and Find operation. Try to make the screen as functional and user friendly as possible.

Attachment:- Activity Lab 8.rar

Reference no: EM132991031

Questions Cloud

Define the specific ethical issue : The selected real-world scenario should reflect a significant ethical issue that resulted from a decision of an organizational leader, politician, or a group of
How might quality control be carried out at a bank : How might quality control be carried out at a bank? How might quality control be carried out at a fast-food restaurant?
Standard deviation for the stock over period : The Allied Group has acquired Kramer Industries and is now considering additional investments. They have determined that there is a firm that is a good fit for
Discrimination complaints can impact an organization : Explain how harassment or any form of discrimination complaints can impact an organization.
Create a movie data maintenance screen : Create a Movie Data Maintenance Screen as below. Provide Navigation Buttons, and buttons for various CRUD operation and Find operation
What is the annual rate of interest on loan : What is the annual rate of interest on this loan? (Use 365 days in a year. Do not round intermediate calculations. Round the final answer to 2 decimal places.)
Explain the nature of international negotiations : Explain the nature of International Negotiations. Is it a science? Is it art? Develop the subject and explain details.
How does instagram use databases : How does instagram use databases?
What are the elements included in the cost framework : What are some of the managerial practices and strategies used to connect value to quality? What are the elements included in the COST framework?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd