Jon
Fri Mar 14 09:46:06 CDT 2008
Andy <andyj@med-associates.com> wrote:
> >
> > When you say "Linq" - which flavour are you using? LINQ to SQL? Entity
> > Framework? Some other provider?
>
> Oh sorry, I'm using Linq to Sql.
And was the code you've shown for the association the code created by
the LINQ to SQL designer, or was it hand-written?
The model I've got in my test app has a lot more code for the setter...
however, it all works. For example, in my test defect database, I've
got:
using (var context = new DefectModelDataContext())
{
context.Log = Console.Out;
Console.WriteLine("Loading defect");
var defect = (from bug in context.Defects
where bug.Summary.Contains("Welsh")
select bug).Single();
Console.WriteLine("Using Project property...");
Console.WriteLine("Project={0}", defect.Project.Name);
}
The output is:
Loading defect
SELECT [t0].[DefectID] AS [ID], [t0].[Created], [t0].[LastModified],
[t0].[Summary], [t0].[Severity], [t0].[Status], [t0].
[AssignedToUserID], [t0].[CreatedByUserID], [t0].[ProjectID]
FROM [dbo].[Defect] AS [t0]
WHERE [t0].[Summary] LIKE @p0
-- @p0: Input NVarChar (Size = 7; Prec = 0; Scale = 0) [%Welsh%]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build:
3.5.21022.8
Using Project property...
SELECT [t0].[ProjectID], [t0].[Name]
FROM [dbo].[Project] AS [t0]
WHERE [t0].[ProjectID] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build:
3.5.21022.8
Project=Skeety Media Player
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
World class .NET training in the UK:
http://iterativetraining.co.uk