O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Joining two entities using LINQ

If two tables are joined by a foreign key relationship, their corresponding entities will have a navigation defined between them. However, if the tables are not joined by a foreign key, navigation does not exist. Even then, if they have common columns/fields, they can be joined using LINQ. In this recipe, we will use LINQ to join entities representing tb_Users and tb_FileStorage to retrieve all the files uploaded by a particular user.

How to do it...

  1. Launch SQL Server Management Studio 2012.
  2. Add a new column to tb_FileStorage. Name it User_ID and set its data type to int.
  3. Create a project of the type Windows Forms Application in Visual Studio 2012. Name it TwoTableJoin.
  4. In Solution Explorer, right-click on the project ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required