i have 3 entities:
goods [gid(pk), goodname] persons [pid(pk), personname] roles [rid(pk), rolename]
but need associate these object each other. in other words, each can have many persons in many roles. have table in db 3 fields (gid, pid, rid)
for example:
book (gid#1), can have 3 associated persons: 1. jack (pid#1) in role author (rid#1) 2. jack (pid#1) in role editor (rid#2) 3. bill (pid#2) in role painter (rid#3)
how can map in poco format in entity framework 4?
i believe have create personroles header store person-role relation, access person+role via one:
personroles [prid(pk), personname, rolename]
(note: withnow entitykey, relationships, ef eliminate entity , give direct person.roles entity, can access via book.persons.select((p) p.roles)
).
personrole#1: jack#1/author#1 personrole#2: jack#1/editor#2 personrole#3: bill#2/painter#3 book.personrole = context.personroles. singleordefault((pr) => pr.person.personid == 1 && pr.roleid == 1);
note: main lang vb.net apologize pseudu code above, hope idea.
update
it should like:
<datacontract(isreference:=true)> <knowntype(gettype(good))> <knowntype(gettype(person))> <knowntype(gettype(role))> partial public class goodpersonrole implements iobjectwithchangetracker implements inotifypropertychanged <datamember()> public property goodid() integer return _goodid end set(byval value integer) if not equals(_goodid, value) if changetracker.changetrackingenabled andalso changetracker.state <> objectstate.added throw new invalidoperationexception("the property 'goodid' part of object's key , cannot changed. changes key properties can made when object not being tracked or in added state.") end if if not isdeserializing if isnot nothing andalso not equals(good.goodid, value) = nothing end if end if _goodid = value onpropertychanged("goodid") end if end set end property private _goodid integer <datamember()> public property good() return _good end set(byval value good) if _good isnot value if changetracker.changetrackingenabled andalso changetracker.state <> objectstate.added andalso value isnot nothing ' dependent end of identifying relationship, principal end cannot changed if set, ' otherwise can set entity primary key same value dependent's foreign key. if not equals(goodid, value.goodid) throw new invalidoperationexception("the principal end of identifying relationship can changed when dependent end in added state.") end if end if dim previousvalue = _good _good = value fixupgood(previousvalue) onnavigationpropertychanged("good") end if end set end property private _good end class
(part generated entity ado.net vb poco entity generator)
i copied 'good' id , nav. property should 3 of them.
Comments
Post a Comment