A couple things. First, you should only submit your changes when you have made all the changes. You don't need to call SubmitChanges every time you create a new attendee.
Create all three first InsertOnSubmit each one, then make a single call to SubmitChanges LINQ to SQL will generate more efficient, chunkier calls that way Second, I'm a little confused about the attendee loading issue. They should lazy load on the first access of the Attendee property. Each individual Conference would incur a separate query when its property is first accessed, so this isn't the most efficient way to handle it.
You can tell L2S to pre-load all attendees for each Conference object that you load. You would do that with the DataLoadOptions class: using (var context = new SomeContext(...)) { var options = new DataLoadOptions(); options. LoadWith(c => c.
ConferenceAttendees); context. LoadOptions = options; var conferencesWithAttendees = from c in context. Conferences where c.
Year = DateTime.Now. Year select c; foreach (var conferenceWithAttendee in conferencesWithAttendees) { conferenceWithAttendee. PrintAllAttendeeNames(); } }.
A couple things. First, you should only submit your changes when you have made all the changes. You don't need to call SubmitChanges every time you create a new attendee.
Create all three first, InsertOnSubmit each one, then make a single call to SubmitChanges. LINQ to SQL will generate more efficient, chunkier calls that way. Second, I'm a little confused about the attendee loading issue.
They should lazy load on the first access of the Attendee property. Each individual Conference would incur a separate query when its property is first accessed, so this isn't the most efficient way to handle it. You can tell L2S to pre-load all attendees for each Conference object that you load.
You would do that with the DataLoadOptions class: using (var context = new SomeContext(...)) { var options = new DataLoadOptions(); options. LoadWith(c => c. ConferenceAttendees); context.
LoadOptions = options; var conferencesWithAttendees = from c in context. Conferences where c. Year = DateTime.Now.
Year select c; foreach (var conferenceWithAttendee in conferencesWithAttendees) { conferenceWithAttendee. PrintAllAttendeeNames(); } }.
Thanks for the first point, good to know and I will do from now on. I am still having problems. Yes, lazy loading normally works fine for me too.It must be something really simple!
See above: I have updated to explain the code I am using to load in the Conference and iterate through the Attendees. But the Count is always 0! – Aaron Sep 3 '10 at 5:22 I am a moron.
I have declared the dataContext as static! GRRR! Many thanks for your help and sorry to waste your time.
1 point. – Aaron Sep 3 '10 at 6:00 Generally speaking, a DataContext should NEVER stick around for longer than the time it takes to do some work. The DataContext is a unit of work class, so making it a field or a property of a class is a bad idea.
Create as late as possible, dispose of as early as possible, and create a new instance every time you perform work in a unit. – jrista Sep 3 '10 at 15:12.
I have LINQ to SQL (C# 3.5 / SQL Server) working well, with a simple relationship in place between two tables Conferences and ConferenceAttendees. Works great and I see the 3 new attendees appear in the database. But it doesn't have any related Attendees attached to it!
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.