tsunami
log in
email
password
links
newest items
tag list
syntax reference
tag:tsunami
history
is primarily about
Thoughts on Blogging
Data Playground
HB1: compare pcns and data sources
PowerShell: Navigate-Clipboard
C# 3.0: SelfJoinByOffset
tsunami suggestions
tsunami specifications
ASP.NET Authentication and Authorization
item name
tags
==SQL Setup {{ create table Parent ( parent_pk int identity primary key, name varchar(20) not null ) create table Child ( child_pk int identity primary key, parent_fk int not null foreign key references Parent (parent_pk), name varchar(20) not null ) insert Parent (name) select 'Parent A' union select 'Parent B' insert Child (parent_fk, name) select 1, 'Child 1' union select 1, 'Child 2' union select 2, 'Child 3' }} ==LINQ Setup Add a _LINQ to SQL Classes_ item to your C# project, then browse the database used for the SQL Setup and drag both the Parent and Child tables onto the "designer" to invoke code generation. ==C# =Notes - `My` in `MyDataContext` gets replaced with the name of your _LINQ to SQL Classes_ object - Visual Studio 2008 pluralizes tables very simplistically, resulting in `Childs` instead of `Children` - one could just iterate over `dc.Parents` in the loop below =Code {{ using (var dc = new MyDataContext()) { var parents = from p in dc.Parents select new { Name = p.name, Children = p.Childs }; foreach (var p in parents) { Console.WriteLine(p.Name); foreach (var c in p.Children) Console.WriteLine(" " + c.name); } } }} =Output {{ Parent A Child 1 Child 2 Parent B Child 3 }}
some permissive license goes here
contact