I'm using LINQ and a DataContext to return a collection of objects from a SQL Server table. The table is named "Widgets" and the corresponding C# class I'm using is shown below. The Widgets table contains a Name column, and a TypeID column which is a foreign key to another table of widget types.
[Table(Name = "Widgets")]
public Class Widget
{
[Column(Name = "Name")]
public String Name{get;set;}
[Column(Name = "TypeID")]
public int TypeID{get;set;}
}
Now I'd much rather be able to access a widget's type by the type name rather then ID as shown below. But the type name comes from another table then the Widget, WidgetTypes.
[Table(Name = "Widgets")]
public Class Widget
{
[Column(Name = "Name")]
public String Name{get;set;}
[Column(Name = "TypeID")]
public int TypeID{get;set;}
//NEW PROPERTY
public String TypeName(get;set;)
}
Is there some way to do a JOIN with a LINQ DataContext that will return data from multiple tables in a database as a single object?
Update:
Here's my DataContext
class WidgetsContext : DataContext
{
public WidgetsContext(string connection):base(connection)
{
}
public Table<Widget> Widgets;
public Table<WidgetType> WidgetTypes;
}