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

  How does your online business fulfil customer needs

How does your online business fulfil customer needs - Revenue Model - how does your online business earn revenue and have a positive return on investment?

  Write a program that lets the user enter the total rainfall

You've been asked to write a program that lets the user enter the total rainfall for an unknown (ahead of time) number of months into a linked list.

  What value does having all these scope reservations have

What value does having all these scope reservations have in an enterprise environment?

  Describe the different identification method

Describe the different identification methods that organizations can use to identify their employees and to grant access to the organizational

  Convert the character from upper case to lower case

Write a program that requests the user to enter an alphabetic character. Then convert the character from upper case to lower case or lower case to upper case.

  Identify main functions of your proposed information system

Identify the main functions of your proposed information system and why they are important to the business. Describe what types of data your information system.

  Write a html files function that computes a taxi fare

Write a HTML and JavaScript files function that computes a taxi fare.

  Write down an object oriented program in java

take a rectangular matrix of cells, each of which can contain an organism. If the matrix is viewed as extending indefinitely in both directions, then each cell has eight neighbors, the eight cells surrounding it.

  Integrated development environments ides are specialized

integrated development environments ides are specialized software packages that help programmers to write a program. in

  Calculate the displacement thickness of the boundary layer

Air at 26°C and 1 atm pressure flows normally to a 5 cm diameter circular cylinder at a velocity of 9 m/s. It can be shown from potential flow theory.

  Write a program which prompts a user to enter his first name

Write a program which prompts a user to enter his first name. There it greets the user in this format: Hello first_name how are you?

  Which one was your preferred productivity software

Now that you've worked in both Microsoft Office and G Suite, which one was your preferred productivity software? What are the strengths and disadvantages.

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