it should be pretty simple.
My LINQ to SQL (C # 3.5 / SQL Server) works fine for me, with a simple relationship between the two Conference tables and ConferenceAttendees .
I already created and completed the Conference , then I add 3 ConferenceAttendees with the following code (repeated 3 times):
ConferenceAttendee NewAttendee = new ConferenceAttendee();
NewAttendee.ConferenceId = ConferenceID;
NewAttendee.Name = ContactName;
NewAttendee.Email = ContactEmail;
db.ConferenceAttendees.InsertOnSubmit(NewAttendee);
db.SubmitChanges();
Works great, and I see that 3 new members appear in the database.
UPDATE:
Then, using the new datacontext, I try the following:
string Names = String.Empty;
Conference RequestedConference = db.Conferences.FirstOrDefault(x => x.ConferenceId == ConferenceID);
foreach (ConferenceAttendee Attendee in RequestedConference.ConferenceAttendees)
Names += Attendee.Name + ", ";
But he has no Attendees attached to him! (They definitely exist in the database and were committed). But RequestedConference.ConferenceAttendees always has a score of 0, so the loop is never entered.
foreach (ConferenceAttendee Attendee in this.ConferenceAttendees)
{ Names += Attendee.Name; }
Partial Class, , PrintAllAttendeeNames().
, datacontext LINQ, ?
(:
db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
..)
. dataContext . , .
:
public static MyDataContext db = new MyDataContext(ConfigurationManager.ConnectionStrings["MyDBConnection"].ConnectionString);
, , !!!
public MyDataContext db = new MyDataContext(ConfigurationManager.ConnectionStrings["MyDBConnection"].ConnectionString);