views:

2833

answers:

4

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?

A: 

You cannot put more than one object/datasource on a datagrid. You will have to build a single ConceptObject that combines the exposed properties of the part Entities. Try to use DB -> L2S Entities -> ConceptObject. You must be very contrived if the DB model matches the ConceptObject field-for-field.

Jarrett Meyer
+2  A: 

(EDIT misunderstood the question, revising my answer to the following)

Your LinqDataSource could point to a view, which allows you to overcome the problem of not being able to express a Join in the actual element. From "How to: Create LINQ to SQL Classes Mapped to Tables and Views (O/R Designer)":

The O/R Designer is a simple object relational mapper because it supports only 1:1 mapping relationships. In other words, an entity class can have only a 1:1 mapping relationship with a database table or view. Complex mapping, such as mapping an entity class to multiple tables, is not supported. However, you can map an entity class to a view that joins multiple related tables.

sixlettervariables
Yes, but how do I do this using the LINQDataSource object?
Norge
A: 

You are best using a ObjectDataSource when you wnt to do more complex Linq and bind your Grid to the ObjectDataSource. You do however need to watch out for Anonymous types that could give you some trouble, but anything is posible...

MrHinsh
+1  A: 

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.

naspinski