Hi, I solved this problem by using "Add" instead of Attach. This does not make sense since Add is used for entities that are none existence. But, it works despite that both Group and Student already exist. Below is the code:
using (var db = new ManyToManyContainer())
{
var existingStudent = (from s in db.Students
where s.RegNo == "X1"
select s).FirstOrDefault<Student>();
var existingGroup = (from g in db.Groups
where g.GroupName == "G1"
select g).FirstOrDefault<Group>();
existingStudent.Groups.Add(existingGroup);
db.SaveChanges();
success = true;
Thanks all the same.