Is is possible to map a many to many relationship without having a navigation property on one of the ends? For example I have some widgets and some users who can star particular widgets. I'd like to be able to see what widgets a user cares stars, but I don't really care about seeing all the users who have starred a particular widget
Widget.cs
public int Id { get; set; }
public string Name { get; set; }
User.cs
public int Id { get; set; }
public string Username { get; set; }
public ICollection<Widget> StarredWidgets { get; set; }
With this setup, EF will generate a one-to-many relationship from Widgets to Users. However, it needs to be a many to many. I realize I could add a public ICollection<User> Users
to Widget.cs
, but just seeing if there was another way around this.
myUserPrefObj.StarredWidgets.Add(myWidget)
the entry gets added to the join table correctly. However, later when I try to reloadmyUserPrefObj
using a different db context, theStarredWidgets
property is null. Any ideas? – Ingravescent