entity, fk's, inherit.. relationship..

Posts   
 
    
zee
User
Posts: 35
Joined: 24-Jul-2008
# Posted on: 29-Jul-2008 21:46:14   

I have a strange question...

lets stay i have a table called Media (it holds the various media a store holds)

Media has MediaName (string), MediaTypeid(int, FK), LicenseTypeid(int, FK)... so., to "correctly" make it work i would do a Dim Media as new MediaEntity and because the MediaTypeid is a fk to the MediaType Table: ID, MediaName (1: CD, 2: Tape.....)., i would just do a Media.MediaTypeid = 1 (or 2 if it was a tape)... same applies to licensetypeid..

my question is... i can see that i actually have access to Media.MediaType (because of the relationship?) what happens if i do Media.MediaType.MediaName = "ABC" would that cause an error... OR if i did a Media.Save.... would that create a NEW entry into MediaType as 3:ABC and then in my Media table... add the value 3 ?

im sure i could try it out,. but i just wanted to be sure... i dont have access to the db yet simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jul-2008 05:45:14   

Hi zee, this is how that works:

// assuming MediaEntity's PK is identity
Media myNewMedia = new MediaEntity();
myNewMedia.MediaName = "somevalue";
// more media fields...

// assuming MediaTypeEntity's PK is identity
myNewMedia.MediaType = new MediaTypeEntity();
myNewMedia.MediaType.MediaTypeName = "someMediaTypeValue";
// more mediaType fields...

// Save recursively. This will save both new media and new mediaType, and the PK-FK sync 
// will take care of assigning the the MediaTypeId to the new media entity.
myNewMedia.Save(true);

For more information, read this manual section.

David Elizondo | LLBLGen Support Team
zee
User
Posts: 35
Joined: 24-Jul-2008
# Posted on: 31-Jul-2008 21:55:09   

thank you... how would you do it if it was a 1 to many relation?

meaning

MEDIA ...mediaid ..mediatname.....

MEDIALANGUAGE ...mediaid ...languageid ...autoseqid...

LANGUAGE ...languageid ...languagename

i am able to do create a new media entity., add values,. but because medialanguage is an entitycollection it has made it read only...

i looked at dim newmedialanguage = medialanguagentity newmedialanguage .mediaid.........................

and then a media.medialanguage.add(newmedialanguage)

followed by a media.save(true).... it saved the media., but not the media language.. simple_smile

zee
User
Posts: 35
Joined: 24-Jul-2008
# Posted on: 31-Jul-2008 22:07:31   

i take it back simple_smile it works... duno why the db didnt show me the data the first time.,