I am fairly new to link and entity framework. Apparently others have had the same issue I am having and there are excellent explanations of the issue here which all make sense in theory. However I cant seem to get the correct syntax to fix MY issue, nor do I understand it enough to decide what would be the BEST choice. The offending code is:
public void ClearAllFilesFromUser(Guid userID)
{
using (DBEntities db= new DBEntities())
{
var filez = (from p in db.Files select p);
aspnet_Users user = (from p in db.aspnet_Users
where p.UserId == userID
select p).First();
foreach (var file in filez)
{
if (file.aspnet_Users.Contains(user))
{
file.aspnet_Users.Remove(user);
}
}
db.SaveChanges();
}
}
The code produces the error at if (file.aspnet_Users.Contains(user))
. I am trying to delete all entries from the junction table in the database for a particular user. Not sure what other information is needed. Please advise and thanks in advance.