c# - Map many to many relation in entity framework -


i have sql server database , c# win forms application , using entity framework.

in database have following tables :

table joint(       jointid       firstname       fathername       lastname) 

which represent joint in gym , every joint has closet, , every joint has 1 closet , each closet can rent 1 joint. thought 1 one relation don't know if it's true anyway closet table :

table closet(    closetid    number) 

but @ same time want keep history each closet because maybe rent 2 months , else rent same closet after first 1 want know each joint rent closet, , want know own know , how payed rent of closet, want start time, end time, price.

at last figured out want third table between above tables , many many relation created :

table closethistory(    jointid     fk    closetid    fk    starttime    endtime    price) 

and think right not sure , not problem. problem when update entities database relation between joint , closet not created , create joint entity stand alone , closet entity doesn't contain starttime, endtime, price attributes, , closethistory not created , true because table between tow tables in many many relation not represented entity, if remove startdate , enddate, price fields closethistory table , re pdate entities works , relation created can't save starttime , endtime , price closets

can me please ??

and sorry explanation, , sorry english language know it's bad :)

you can use 4 table scheme , pair of insert , delete triggers resolve issue.enter image description here

create trigger [dbo].[addtrigger]    on [dbo].[closetjoint]    after insert  begin     set nocount on;     declare @jointid int;     declare @closetid int;      set @closetid = (select closetid inserted);     set @jointid = (select jointid inserted);      insert closethistory(closetid, jointid, starttime)      values(@closetid, @jointid, getdate()) end  create trigger [dbo].[deletetrigger]    on [dbo].[closetjoint]    after delete  begin     set nocount on;     declare @jointid int;     declare @closetid int;      set @closetid = (select closetid deleted);     set @jointid = (select jointid deleted);      update closethistory set endtime = getdate()     closetid = @closetid , jointid = @jointid , endtime null end 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -