I have a database that consists in keeping calendars, those calendars are spread out in several tables that uses FK to each tables…
Everything works but now I want to be able to say
Create a new calendar with all it’s features based on calendar Id: 62
I was trying one way but it’s terrible, witch is going through all my repository Update area and fire each onde that will create new content on each table…
Is there a faster Solution?
A way that we could simply say
db.Entity<Calendar>(CalendarId).CloneAsNew();
so I would end up with :
[Table Calendars]
calendar_id Name Url
62 Cal_A url_A
74 Cal_A url_A
[Table CalendarContents]
content_id calendar_id type img_background img_top
14 62 1 bkg.png top.png
26 74 1 bkg.png top.png
having only one calendar before, as
[Table Calendars]
calendar_id Name Url
14 Cal_A url_A
[Table CalendarContents]
content_id calendar_id type img_background img_top
14 62 1 bkg.png top.png
P.S. If you detach and attach it again like
context.Detach(entity);
entityCollection.Add(entity);
we loose all references :-/
EF doesn’t provide any way to clone entity graph. At this time you have to general solutions: