Use joins in Entity Framework with a DB context and a LINQ query.

Linq6.jpg

Click “Next”, the following window will appear:

Linq7.jpg

Select the required database objects as per your needs and click on the “Finish” button.

An edmx file will be added into the solution as per the image show under the following:

Linq8.jpg

These are the very basic steps to create an entity object from an existing database as shown above. Now let’s proceed further and get to the core topic to use Joins with Entity Framework.

Now open the RegisterController class file and write my code in Action “Verify” also as shown in the following image:

Linq9.jpg

You can see the code snippet in the above diagram states that we are using an inner join on two tables, Orders and OrderDetails, and return the result to the view (that is of type OrderModel having the following code snippet).

Linq10.jpg

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s