# 2.1: Entity Framework, References, Using Statements

In this module we'll address the errors caused by moving the `IdentityModels.cs` file to a new assembly.

## Purpose

After moving `IdentityModels.cs` to **ElevenNote.Data** you should be seeing some errors. These errors are a result of us needing certain references and packages for our solution. We'll add those items now. Currently, the code in the **.WebMVC** layer can't see the `IdentityModels.cs`. It needs access. Also, the **.Data** layer does not have the Entity Framework package installed. `IdentityModels.cs` needs that package to operate.

## Assembly Name

The first thing we'll correct is the assembly name that accompanies the `IdentityModels.cs` file.

1. Go to the `IdentityModels.cs` file.
2. Update the namespace to align with our current namespace:

   ![namespace](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LDgKn7k5LYR_87ejtWS%2F-LDgKpcDdalhv2fF5FSz%2F2.1-namespace.png?generation=1527604798066692\&alt=media)

## Add Entity Framework to the Projects

Next, we'll install Entity Framework. Entity Framework (EF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. In this app, Entity Framework will help us connect to our database, and it will allow us to complete CRUD operations in our database.

Install EF by doing the following:

1. Right click on the solution and choose **Manage Nuget Packages for Solution**.
2. Note that it will sometimes default to the 'Installed' tab.&#x20;
3. Click the browse tab. In the search bar, browse for **EntityFramework**.
4. Choose **Microsoft.AspNet.Identity.EntityFramework**.
5. Click **Project**.
6. Click **Install**.

   ![EntityFramework](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxDFiooY8E6XMc1wGw%2F-LAxDHqd4d6i7xi7CYMQ%2F2.1-A.png?generation=1524666807540455\&alt=media)
7. Close the NuGet Package Manager.

## Add References

We'll add a few references for our MVC project now. References, if you don't know, allow one assembly to access public classes in other assemblies. The web project needs to communicate with the other projects in our solution. As we shall soon see, it needs to know about the .Data layer, the .Services layer, and the .Models layer. This is done with references.

When adding references, it's smart to think with this formula:

"Does x assembly need to know about or use the y assembly?"

**Does the web layer need to know about the service layer?** Yes, the web layer will use the service to query the db.

**Does the web layer need to know about the Data layer?** Yes, the web layer needs the IdentityModels that we just moved.

**Does the service layer need to know about the WebMVC layer?** No, the service layer will have the duty of querying the db. It doesn't care where the query is coming from.

We'll work with this questioning as we operate.

## Steps

Let's work with the references:

1. First, let's find the errors to fix by pressing `CTRL + SHIFT + b` to build the project. If you don't see the Error Output at the bottom, go to the View tab and choose `Error List`.
2. Use the `Error List` to troubleshoot and navigate to errors.
3. You should see a list of errors which may vary slightly from the screenshot below:

   ![Reference Errors](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxCBs_vddsHcfvN2Mp%2F-LAxCE8wg0hY8U4KfXO_%2F2.1-B.png?generation=1524666535777239\&alt=media)
4. Right-click on **ElevenNote.WebMVC** and go to **Add -> Reference**
5. Click on **Projects -> Solution**
6. Select the ElevenNote.Data, ElevenNote.Services & ElevenNote.Models projects and click **OK**. You should see this view:

   ![Add References](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LD70E9vsOnMSIHsgt1C%2F-LD70FmKtR6r_Dr3Uvhp%2F2.1-web-references.PNG?generation=1526995423604659\&alt=media)

## Add Using Statements

Because we moved the `IdentityModels.cs` file from the WebMVC project to the **Data** project, we need to bring in using statements for the Data project.

1. Again, press`CTRL SHIFT B` to build the project
2. You should have more errors - see below for approximation:

   ![Using Statement Errors](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxCBs_vddsHcfvN2Mp%2F-LAxCEKU-sJZhdvySZsO%2F2.1-D.png?generation=1524666531204006\&alt=media)
3. Double click on the first error to go to the code with the error
4. Click on the error in the file and `CTRL .` to bring in the using statement at the top:

   ![CTRL .](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxCBs_vddsHcfvN2Mp%2F-LAxCEKVgDTKq2OQzBQD%2F2.1-E.png?generation=1524666534832299\&alt=media)
5. It should bring in the following using statement at the top of your file (your line #'s may differ)

   ![Using Statement](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxCBs_vddsHcfvN2Mp%2F-LAxCEKW4R0qRyLP4MEC%2F2.1-F.png?generation=1524666535504710\&alt=media)
6. `CTRL SHIFT B` again to build the project. By the way,`CTRL SHIFT B` saves everything first, and then builds a library for the project.
7. There should be more errors after building. To remove them, repeat the above process until all errors are gone.

Now might be a good time to back up your code: ![Git](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAwyv0-ttugakHO6zeV%2F-LAwyxUd0dcYSLXYb-5s%2Fdevicons_github_badge.png?generation=1524662787257488\&alt=media)
