c# - Link Tables with Properties in EF6 Code First -
i have situation code first ef6 need create many-to-many mapping (easy enough) generated relationship table needs contain properties of own. here's simplified example of have:
public class journey : entity { public string name { get; set; } public datetime start { get; set; } public virtual icollection<point> points { get; set; } } public class point : entity { public dbgeography geolocation { get; set; } public string name { get; set; } public virtual icollection<journey> journeys { get; set; } }
the "entity" class contains primary key.
this of course create relationship table foreign keys "point" , "journey" table primary keys. great, if want add properties link table? such datetime
property called arrivaldate
holds time of arrival @ point.
you argue can add property "point" class but want table hold list of physical points used in application, without duplicates (a single point used in multiple journeys, each different arrival dates). therefor need hold property elsewhere, link table ideal here.
the solution can think of create actual relationship class:
public class journeypoint : entity { public int journeyid { get; set; } public int pointid { get; set; } public datetime arrivaltime { get; set; } public virtual journey journey { get; set; } public virtual point point { get; set; } }
and modify journey
, point
classes have one-to-many relationship journeypoint
class. adds complication , isn't particularly semantic:
... journey myjourney = amethodtogetmyjourney(); point firstpoint = myjourney.journeypoints[0].point. ...
that doesn't seems make sense , confuse other developers. i'm asking possible @ all?
Comments
Post a Comment