Search code examples
linqlinq-to-sql.net-3.5dynamic-data

.NET 3.5 Linq Datasource and Joins


Have been trying out the new Dynamic Data site create tool that shipped with .NET 3.5. The tool uses LINQ Datasources to get the data from the database using a .dmbl context file for a reference. I am interseted in customizing a data grid but I need to show data from more than one table. Does anyone know how to do this using the LINQ Datasource object?


Solution

  • If the tables are connected by a foreign key, you can easily reference both tables as they will be joined by linq automatically (you can see easily if you look in your dbml and there is an arrow connecting the tables) - if not, see if you can add one.

    To do that, you can just use something like this:

    <%# Bind("unit1.unit_name") %>
    

    Where in the table, 'unit' has a foreign key that references another table and you pull that 'unit's property of 'unit_name'

    I hope that makes sense.