Posts

Showing posts with the label LINQ

Entity Framework (Database First) Part 4: Using the LINQ and Projection To SELECT Columns From Entities

Image
In the last blog we just selected the Products entities from the NorthwindEntities with this Linq Query. var query = from prod in nwctx.Products select prod; It gets the job done but, the GridView displays the CategoryID and SupplierID as integers, which is not very useful to your users. Plus, we don't want to display the ProductID. In this blog we are going to refine the LINQ query so that the GridView only display the columns that we want to display with Projection and Anonymous Types.  Projection is to transform an object into a new form with only the properties that you want in the new form.  In our case we want to transform the Products DataSet to a new form that only returns the data that we want. The resulting GridView after projection is looks like this. Notice that the ID column is hidden and the Category and Supplier shows the actual Category name and the Supplier name. Here are the steps: 1.  Open up the project that you've completed on the last blog....