Hello, today I was working with a sample for a colleague and got a
problem. The sample was quite simple, with a micro cds database like:

CREATE TABLE ARTIST
(
   NUM_REGISTO NUMBER PRIMARY KEY NOT NULL,
   NOME VARCHAR2(200) NOT NULL,
);

CREATE TABLE ALBUM
(
   NUM_REGISTO NUMBER PRIMARY KEY NOT NULL,
   NUM_ARTIST REFERENCES ARTIST(NUM_REGISTO) NOT NULL,
   TITULO VARCHAR2(200) NOT NULL,
);

CREATE TABLE TRACK
(
   NUM_REGISTO NUMBER PRIMARY KEY NOT NULL,
   NUM_ALBUM REFERENCES ALBUM(NUM_REGISTO) NOT NULL,
   NOME VARCHAR2(200) NOT NULL,
   DURACAO NUMBER NOT NULL
);

After creating the code with dbmetal, I was trying to add tracks to
albums. For existing albums, the following code works fine:

//----------------
Album album = (from a in database.Album
                           where a.Numregisto == 123
                           select a).SingleOrDefault();
if (album != null)
{
        Track t = new Track();

        t.Duracao = 10;
        t.Nome = "track1";
        t.Numregisto = 1;

        album.Track.Add(t);

        database.Track.InsertOnSubmit(t);

        database.SubmitChanges();
}
//----------------

On new albums, I got confused. If I do:

//----------------
Album album = new Album();

album.Numregisto = 4444;
album.Titulo = "tttt";
album.Numartist = 1231;

Track t = new Track();

t.Numalbum = album.Numregisto;
t.Duracao = 10;
t.Nome = "track1";

database.Album.InsertOnSubmit(album);
database.Track.InsertOnSubmit(t);

database.SubmitChanges();
//----------------

everything is inserted. However, the Album.Track property (an entity
set) only gets populated after the SubmitChanges (which is not good
for UI applications where a gridview may be bound to that property)

If I manually add the track to the album tracks with
"album.Track.Add(t)" I get an InvalidOperationException ("The
EntitySet is already loaded and the source cannot be changed").

Also, does the order for InsertOnSubmit matter? I thought we could,
for example, call InsertOnSubmit for the track before the album, as
the update/insert order would be automatically calculated.

How's this typically done? I've tried so many combinations that I'm
afraid I may be missing something trivial here.

Thanks,

Pedro Ferreira

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to